单击按钮时 NSMutable 数组到 UITableview

发布于 2024-12-15 17:51:08 字数 2500 浏览 2 评论 0原文

我想在点击收件箱按钮时在 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:@""];
            }
  }
}

到目前为止我已经尝试过,但找不到任何指南来在按钮点击事件时放置此内容,这无论如何都不起作用无论如何显示一个空的表格视图

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随遇而安 2024-12-22 17:51:08

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

这将刷新 tableView。

不过,我建议您查看 UITableView 的文档,了解如何使用 -(void) beginUpdates-(void) endUpdates 这样您可以获得更好的视觉体验并让表视图对进入的行进行动画处理。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文