我在UIView的控制器产生一个UITableView无法reloaddata(UITableView的)
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 470, self.view.frame.size.height) style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
NSLog(@"tableView is '%@'",self.tableView);
}
所述的NSLog结果:“是的tableView'<的UITableView:0x7c60c00;帧=(0 0; 470 1004); clipsToBounds = YES; gestureRecognizers =;层=; contentOffset:{0,0}>'”
的refreshTableView方法将被调用,当itemArray被其他控制器改性
**SideBarViewController *sideBarViewController = [[SideBarViewController alloc]init];
[sideBarViewController refreshTableView];**
-(void)refreshTableView {
[self createItemArray];
NSLog(@"reload itemArray->%@",self.itemArray);
NSLog(@"tableView is '%@'",self.tableView);
[self.tableView reloadData];
}
不知何故,NSLog的结果变成:“tableView是'(null)'”。和tableView将不会被重新加载。
为什么?请帮忙。谢谢。
更新:
itemArray的NSLog的很好:
改变之前 重装itemArray - >( “test.md” )
变更后 重装itemArray-> ( “test.md”, “test2.md” )
UPDATE2:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.itemArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [self.itemArray objectAtIndex:indexPath.row];
return cell;
}
更新3:
.h
@interface SideBarViewController : UIViewController<IIViewDeckControllerDelegate,UITableViewDataSource,UITableViewDelegate>
.m
@interface SideBarViewController()
@property (nonatomic,strong) UITableView *tableView;
@end
@implementation SideBarViewController
@synthesize tableView = _tableView;
更新4: 的
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
方法工作正常,之后删除的行的的tableview是重新加载。
重载表之前,其工作正常? – iPatel 2013-03-28 06:34:07
是的,工作正常,只是无法重新加载tableview – 2013-03-28 06:35:09
您提供的代码看起来很好 - 错误必须在代码的其他地方。 – ColinE 2013-03-28 06:36:08