【发布时间】:2015-04-30 19:18:00
【问题描述】:
我很困惑。
我有 2 个控制器,我们称它们为 controller1 和 controller2。
在 controller1.m 我有这个:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSString *object = self.objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
在 controller2.m 中,我试图在 controller1.m 中重新加载 tableview:
- (void)GetRequest
{
NSArray *tableData = [dataSource.areaData GetPurchaseOrderItems:[NSString stringWithFormat:@"%@%@",areaPickerSelectionString,unitPickerSelectionString]];
if(!purchaseOrder.objects){
purchaseOrder.objects = [[NSMutableArray alloc]init];
}
for(int i = 0; i < [tableData count]; i++){
[purchaseOrder.objects addObjectsFromArray:[tableData objectAtIndex:i]];
NSLog(@"%@",[tableData objectAtIndex:i]);
}
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[purchaseOrder.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
NSLog(@"%@", purchaseOrder.objects);
//[self.tableView reloadData];
}
我尝试了以下方法:
controller1.h:
@property(nonatomic, retain) UITableView *tableView;
controller1.m:
@synthesize tableView;
controller2.h:
#import "controller1.h"
@interface controller2 ()
{
controller1 *purchaseOrder;
}
- (void)viewDidLoad {
purchaseOrder = [[controller1 alloc]init];
}
然后[purchaseOrder.tableView reloadData];
并且我的 tableView 没有重新加载。怎么回事?我不知道我在这里做错了什么。我也收到此警告:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
这是警告:
Local declaration of 'tableView' hides instance variable
【问题讨论】:
-
似乎还有另一个变量名'tableView'。您需要重命名它或确保您的目标是正确的。请显示更多代码以进行检查。
-
这有很多奇怪的地方,但让我们从
purchaseOrder = [[controller1 alloc]init];开始。这将创建一个新controller1。如果你想让purchaseOrder更新,你需要先推送或呈现。我怀疑你可能已经在其他地方有一个controller1,但这个新的与屏幕上可能已经出现的任何东西都没有关系。
标签: ios objective-c xcode uitableview uiviewcontroller