单击按钮时 NSMutable 数组到 UITableview
我想在点击收件箱按钮时在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在
buttonInbox:
选择器末尾调用[[self tableView] reloadData]
。这将刷新 tableView。
不过,我建议您查看 UITableView 的文档,了解如何使用
-(void) beginUpdates
和-(void) endUpdates
这样您可以获得更好的视觉体验并让表视图对进入的行进行动画处理。Try calling
[[self tableView] reloadData]
at the end of thebuttonInbox:
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.