我是 iOS 开发的新手。我正在开发我的项目,它完全基于从 url 解析的 XML。我解析了 XML 数据并存储在一个数组中,但我无法在UITableView
.
这是我的代码。
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
eventarray = [[NSMutableArray alloc]init];
xmlParserObject = [[NSXMLParser alloc] initWithData:webData];
[xmlParserObject setDelegate:self];
[xmlParserObject parse];
for (int i =0; i<[rssOutputData count]; i++) {
Eventlist *log = [rssOutputData objectAtIndex:i];
eventid = log.id;
NSLog(@"%d",eventid);
Invit = log.eventname;
NSLog(@"%@",Invit);
}
[rssOutputData release];
[connection release];
[tblView reloadData];
}
我的数组在这里打印值,但是如何在UITableView
. 我试过了,但我没有在表格视图中获取数据。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"eventCell";
UITableViewCell *cell= [[tableViewdequeueReusableCellWithIdentifier:CellIdentifier]autorelease];
if(indexPath.section == 0)
{
Eventlist *msglist = [eventarray objectAtIndex:indexPath.row];
cell.textLabel.text = msglist.eventname;
cell.textLabel.textColor = [UIColor greenColor];
}
if(indexPath.section == 1)
{
UIButton *viewmoreButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
viewmoreButton.frame = CGRectMake(200.0f, 5.0f, 75.0f, 30.0f);
[viewmoreButton setTitle:@"View More" forState:UIControlStateNormal];
[cell addSubview:viewmoreButton];
[viewmoreButton addTarget:self action:@selector(viewMore:)forControlEvents:UIControlEventTouchUpInside];
}
return cell;
}
感谢你的帮助。