Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

iphone - Error in showing data in tableview

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];
}
}

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...