当按钮单击时,将NSMutable数组转换为UITableview

时间:2020-12-23 20:01:00

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

我想在UITableView中显示我的邮件头当收件箱按钮点击时,我的邮件头被存储在一个NSMutable数组中,

   -(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

到目前为止,我已经尝试过了,但是当按钮单击事件时,我找不到任何指导方针,这无论如何都不管用,它显示的是一个空的tableview

- (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 个解决方案

#1


2  

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

尝试在buttonInbox的末尾调用[[self - tableView] reloadData]:选择器。

This will refresh the tableView.

这将刷新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.

但是,我建议查看UITableView的文档,看看如何使用-(void)开始更新和-(void),这样您就可以获得更好的视觉体验,并让表视图使输入的行动起来。

#1


2  

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

尝试在buttonInbox的末尾调用[[self - tableView] reloadData]:选择器。

This will refresh the tableView.

这将刷新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.

但是,我建议查看UITableView的文档,看看如何使用-(void)开始更新和-(void),这样您就可以获得更好的视觉体验,并让表视图使输入的行动起来。