NSMutable array to UITableview when button clicked

与世无争的帅哥 提交于 2019-12-22 09:55:19

问题


i want to show my email headers in a UITableView when inbox button clicked, my email headers is stored in an NSMutable Array,

   -(IBAction)buttonInbox:(id)sender{

        NSLog(@"Inbox Button Clicked %@",buttonInbox);
        [self select:@"INBOX"];
        NSArray *lines = [self sendCommand:@"fetch 1:* (body[header.fields (from subject date)])"];



        //NSMutableArray *emaiArray= [[NSMutableArray alloc] init];
        NSMutableString *totalEmail= [NSMutableString stringWithString:@""];

        int counter = 0;
        int i =0;
        NSRange tmp;
        for(i=0;i<[lines count];i++)
        {

            NSString *line = [lines objectAtIndex:i];

            //NSLog(@" Burda %@" ,line);
            tmp = [line rangeOfString:@"Date:"];
            if( tmp.location != NSNotFound ) 
            {
                //NSLog(@" Date basildi %@" ,line);
                counter++;
                [totalEmail appendString:line ];

            }

            tmp = [line rangeOfString:@"From:"];
            if (tmp.location != NSNotFound ) {
                //NSLog(@" From basildi %@" ,line);
                counter++;
                [totalEmail appendString:line ];
            }

            tmp = [line rangeOfString:@"Subject:"];
            if (tmp.location != NSNotFound ) {
                //NSLog(@" Subject basildi %@" ,line);
                counter++;
                [totalEmail appendString:line ];
            }
            if (counter==3) {
                [emailList addObject:totalEmail];
                counter =0;
                NSLog(@"total Email %@" ,totalEmail);
                totalEmail = [NSMutableString stringWithString:@""];
            }
  }
}

i have tried this so far but couldnt find any guidelines to put this when button clicked events, this doesnt work any way it shows an empty tableview anyways

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [emailList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:[NSString stringWithFormat:@"Cell %i",indexPath.section]] autorelease];

    }

    cell.textLabel.text = [emailList objectAtIndex: indexPath.row];

    return cell;
}

回答1:


Try calling [[self tableView] reloadData] at the end of the buttonInbox: selector.

This will refresh the tableView.

I would, however, suggest looking at the documentation for UITableView and see how to use -(void) beginUpdates and -(void) endUpdates so you can get a better visual experience and let the table view animate the rows coming in.



来源:https://stackoverflow.com/questions/8116263/nsmutable-array-to-uitableview-when-button-clicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!