【发布时间】:2011-06-29 05:31:17
【问题描述】:
我对 iPhone 开发还很陌生。我使用 coredata 创建了 To-Do List 应用程序。所以,我的表格视图动态更新。 我想将表视图行文本标签添加到 NSMutable 数组(这意味着 row1 文本标签到 MutableArray 的第一个索引位置,row2 文本标签到数组的第二个索引位置)
这是用于 indexpath 方法的表格视图单元格
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *HeroTableViewCell = @"HeroTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HeroTableViewCell];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:HeroTableViewCell] autorelease];
}
NSManagedObject *oneHero = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSInteger tab = [tabBar.items indexOfObject:tabBar.selectedItem];
switch (tab) {
case kByName:
cell.textLabel.text = [oneHero valueForKey:@"name"];
cell.detailTextLabel.text = [oneHero valueForKey:@"secretIdentity"];
break;
case kBySecretIdentity:
cell.detailTextLabel.text = [oneHero valueForKey:@"name"];
cell.textLabel.text = [oneHero valueForKey:@"secretIdentity"];
default:
break;
}
//listData = [[[NSMutableArray alloc] init]autorelease];
//if(indexPath.row==1){
//[listData addObject: cell.textLabel.text];
return cell;
}
注释行是我尝试的方式。但我很难根据需要添加这些数据。 请帮帮我
【问题讨论】:
-
似乎你已经把它弄反了——数据应该来自数组并复制到表格单元格中。您能否编辑您的问题以解释您要完成的工作?
-
您已经从 Core Data 中检索对象。为什么需要将这些单元格中的数据复制到另一个数组中?
-
您可以直接从coredata(tableview数据源)中获取并将其传递给数组吗? mobile.tutsplus.com/tutorials/iphone/iphone-core-data 在此链接中检查 timetablecontroller.m 的代码
-
请停止转发您的问题,改为编辑您的问题!
标签: iphone objective-c ios