在TableView中显示数据时出错 [英] Error in showing data in tableview
问题描述
我正在以这种方式从我希望我应该在部分标题中显示日期的方式获取数据以及事件位置在appDelegate.book1数组中的行中.当此循环首先运行时,然后在第一部分中,它必须在一个部分中显示7行,并且与以后相同,但我并没有被要求
I am getting data using this way from i want that i should display date in section title and the event location in rows which are in appDelegate.book1 array. when this roop runs first then in first section it must show 7 rows in one section and same like that as come but i am not getting required
NSArray *activitiesArray;
for (int j=0;j<10; j++) {
NSDictionary *dictOne = [results objectAtIndex:j];
NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
Date *aDate = [[Date alloc] initWithDictionary:[results objectAtIndex:j]];
[appDelegate.dates addObject:aDate];
[aDate release];
activitiesArray = [dictOne objectForKey:@"events"];
for (int i=0; i<[activitiesArray count]; i++) {
int testcount =[activitiesArray count];
NSDictionary *dictTwo = [activitiesArray objectAtIndex:i];
NSDictionary *eventDict=[dictTwo objectForKey:@"event"];
// NSLog(@"%@ - %@", [dictOne objectForKey:@"date"]);
// NSLog(@"%@ - %@", [dictTwo objectForKey:@"affectedDate"]);
// NSLog(@"%@ - %@", [eventDict objectForKey:@"location"]);
NSInteger*date=[dictTwo objectForKey:@"affectedDate"];
NSInteger*affectedDate=[dictTwo objectForKey:@"affectedDate"];
NSString*appId =[eventDict objectForKey:@"appId"];
NSString*eventId=[eventDict objectForKey:@"eventId"];
NSString*location=[eventDict objectForKey:@"location"];
NSString*municipality=[eventDict objectForKey:@"municipality"];
NSString*title=[eventDict objectForKey:@"title"];
Book1 *aBook=[[Book1 alloc] initWithDate:date affectedDate:affectedDate location:location municipality:municipality title:title];
[appDelegate.books1 addObject:aBook];
int count=[appDelegate.books1 count];
}
}
这是appDelegate.book1的NSLog计数整数num的值是12011-08-09 12:40:31.731 FVN [2409:207]整数num的值为22011-08-09 12:40:31.731 FVN [2409:207]整数num的值为32011-08-09 12:40:31.731 FVN [2409:207]整数num的值为42011-08-09 12:40:31.732 FVN [2409:207]整数num的值为52011-08-09 12:40:31.732 FVN [2409:207]整数num的值为62011-08-09 12:40:31.733 FVN [2409:207]整数num的值为7
this is the NSLog of count of appDelegate.book1 The value of integer num is 1 2011-08-09 12:40:31.731 FVN[2409:207] The value of integer num is 2 2011-08-09 12:40:31.731 FVN[2409:207] The value of integer num is 3 2011-08-09 12:40:31.731 FVN[2409:207] The value of integer num is 4 2011-08-09 12:40:31.732 FVN[2409:207] The value of integer num is 5 2011-08-09 12:40:31.732 FVN[2409:207] The value of integer num is 6 2011-08-09 12:40:31.733 FVN[2409:207] The value of integer num is 7
所以像这个数组一样,我的表格视图应该在第一部分和上面一样显示第7项内容,因为它们是按顺序排列的,所以该怎么做
so like this array my table view should show 7 items in first section adn like wise above as they are in sequence so how to do this
推荐答案
我认为您正在表视图控制器子类中寻找以下两个委托方法.
I think you are looking for the following two delegate methods in your Table view controller subclass.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2; //return the actual number of sections you want
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
if(section == 0)
return 7; //actually return your array1's count
if(section == 1)
return 9; //actually return your array2's count
}
HTH,
Akshay
这篇关于在TableView中显示数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!