Iphone 从appDelegate调用数据时重新加载tableview源
我有一个基于表的应用程序,它将数据存储在mysql服务器上,它会得到更新,并将数据写入nsdictionary以实现持久性。当您更改数据时,表需要更新。但是,如果我放置[self tableview reloadData],应用程序在选择行时崩溃。有没有人知道如何进行表格刷新。我是否需要抛弃这个,从数据中创建一个对象并使用它 谢谢Iphone 从appDelegate调用数据时重新加载tableview源,iphone,nsobject,uitableview,Iphone,Nsobject,Uitableview,我有一个基于表的应用程序,它将数据存储在mysql服务器上,它会得到更新,并将数据写入nsdictionary以实现持久性。当您更改数据时,表需要更新。但是,如果我放置[self tableview reloadData],应用程序在选择行时崩溃。有没有人知道如何进行表格刷新。我是否需要抛弃这个,从数据中创建一个对象并使用它 谢谢 -(void) loadData3;{ MyAppDelegate *AppDelegate = (MyAppDelegate *)[[UIApplic
-(void) loadData3;{
MyAppDelegate *AppDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
self.tableDataSource3 = [AppDelegate.data3 objectForKey:@"Rows"];
NSLog(@"AppDelegate.data3 : %@",AppDelegate.data3 );
NSLog(@"self.tableDataSource3 : %@",self.tableDataSource3 );
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData3];
if(CurrentLevel3 == 0) {
self.navigationItem.title = @"Family";
}
else
self.navigationItem.title = CurrentTitle3;
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
下面是cellForRowAtIndexPath方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSDictionary *dictionary = [self.tableDataSource3 objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:@"Title"];
return cell;
}
我同意这样的解释,即重新加载数据是正确的方法,您需要找到并修复导致崩溃的错误 这里有两件大事要看:
[self.tableView reloadData]是告诉实例变量tableView中的UITableView重新加载数据的正确方法。如果代码崩溃,那么其他地方就有问题;可能是在您的数据源中。谢谢,我会研究这一点,为我开辟新的领域,但我会从那里开始。这里是一个样板示例。注意“dequeueReusuableCell”jazz。(很抱歉格式化…)UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@“MyCellIdent”];如果(cell==nil){cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];}//设置单元格的标签。。。[[cell textLabel]setText:[myArray objectAtIndex:[indexPath indexAtPosition:1]];return cell;@Brad做了一些奇怪的事情,indexAtPosition我从未见过。这行代码只是假设所有单元格标签都来自NSString数组“myArray”。[indexPath indexAtPosition:1]将是第一个节中的单元索引-假设您的tableView只使用了一个节(即,[IndexXPath indexAtPosition:0]将返回节号-对于单个节视图,节号始终为零)@Brad谢谢,情况并非如此,但我很快将使用其他格式。