简体   繁体   English

NSArray和tableview

[英]NSArray and tableview

I'm making a navigation-based application, where i have a file called DataService.m and my RootViewController 我正在制作一个基于导航的应用程序,其中有一个名为DataService.m的文件和我的RootViewController

.m .m

in my DataService.m I'm calling 在我的DataService.m中

-(NSArray*)loadData
{
    AlarmItem *item1 = [[[AlarmItem alloc] initWithTitle:@"TEST2"] autorelease];
    AlarmItem *item2 = [[[AlarmItem alloc] initWithTitle:@"TEST3"] autorelease];
    AlarmItem *item3 = [[[AlarmItem alloc] initWithTitle:@"TEST4"] autorelease];
    AlarmItem *item4 = [[[AlarmItem alloc] initWithTitle:@"TEST5"] autorelease];
    AlarmItem *item5 = [[[AlarmItem alloc] initWithTitle:@"TEST6"] autorelease];

    NSMutableArray *items = [NSMutableArray arrayWithObjects:item1, item2, item3, item4, item5, NULL];

    return items;
}

and in my RootViewCoontroller.mi have 在我的RootViewCoontroller.mi中有

- (IBAction)RefreshAlarmList:(id)sender
{
    XMLDataService *myXML = [[XMLDataService alloc] init];
    [myXML loadData];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
    target:self action:@selector(RefreshAlarmList:)]; 
    self.navigationItem.rightBarButtonItem = refreshButton;
    [refreshButton release];
}

When I run my simulator the tableView is empty.. how can i display my items ? 当我运行模拟器时,tableView为空。如何显示项目?

加载到表视图中后不要autorelease该函数,然后自动释放它,然后您如何将数据显示到表视图中。作为在表视图中重新加载数据的操作。

You can try one thing.Here in the delegate method cellForRowAtIndexPath , in last u should return the cell.It may work. 您可以尝试一件事,在委托方法cellForRowAtIndexPath中,最后您应该返回该单元格。

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {静态NSString * CellIdentifier = @“ Cell”; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; if(cell == nil){cell = [[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle复用Identifier:CellIdentifier]自动释放]; } // Configure the cell. } //配置单元格。 AlarmItem *item = [_items objectAtIndex:indexPath.row]; AlarmItem * item = [_items objectAtIndex:indexPath.row]; cell.textLabel.text = item.tagName;return cell;} cell.textLabel.text = item.tagName;返回单元格;}
[myXML loadData]; 

This is returning an array, which presumably you wish to use as your table's data source, but you are doing nothing with it. 这将返回一个数组,可能您希望将其用作表的数据源,但您对此无所事事。 You need to assign this to an array, which is a retained ivar in your view controller class, _items or items judging by your other comments: 您需要将此分配给一个数组,该数组是视图控制器类, _items或通过其他注释判断的items保留的ivar:

self.items = [myXML loadData];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NSArray列出到TableView - NSArray to plist to TableView 用于表视图的XCode 4.2 NSArray数据库 - XCode 4.2 NSArray database for tableview 使用现有的NSArray对象属性为分段的tableView创建新的NSArray - Use existing NSArray object properties to create a new NSArray for sectioned tableView 在Tableview中触摸屏幕后显示NSArray值 - NSArray Values are Display after touche in screen in Tableview 如何将NSArray拆分为按字母顺序排列的部分,以便与索引tableview一起使用 - how to split NSArray into alphabetical sections for use with index tableview 将返回的json数据保存到NSDictionary或NSArray中以在TableView中显示吗? - Saving returned json data to NSDictionary or NSArray to be displayed in TableView? 为什么tableView titleForHeaderInSection的NSArray objectAtIndex:section错误:空数组的索引0超出范围 - Why is NSArray objectAtIndex:section for tableView titleForHeaderInSection error: index 0 beyond bounds for empty array 请帮我!! 谁能教我IBAction如何仅在单元格上从TableView对ISArray对象使用isEqualToString? - Please Help me!! Would anyone can teach me IBAction how to use `isEqualToString` to an `NSArray` object from TableView only on cell? 排序NSArray并返回NSArray? - Sorting NSArray and returning NSArray? nsarray中的NSLog nsarray - NSLog nsarray in nsarray
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM