我新的目標C和iPhone編程。我似乎無法弄清楚爲什麼當我運行此代碼時沒有單元格填充。 xml內容顯示在控制檯日誌中,xcode不顯示任何錯誤。有任何幫助嗎?的UITableView:NSMutableArray裏沒有出現在表
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if(![elementName compare:@"Goal"]) {
tempElement = [[xmlGoal alloc] init];
} else if (![elementName compare:@"Title"]) {
currentAttribute = [NSMutableString string];
} else if (![elementName compare:@"Progress"]) {
currentAttribute = [NSMutableString string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (![elementName compare:@"Goal"]) {
[xmlElementObjects addObject:tempElement];
} else if (![elementName compare:@"Title"]) {
NSLog(@"The Title of this event is %@", currentAttribute);
[tempElement setTitled:currentAttribute];
} else if (![elementName compare:@"Progress"]) {
NSLog(@"The Progress of this event is %@", currentAttribute);
[tempElement setProgressed:currentAttribute];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (self.currentAttribute) {
[self.currentAttribute appendString:string];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [xmlElementObjects count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [mtableview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.textLabel.text = [xmlElementObjects objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
不要一個答案回答自己的問題。改爲編輯原始帖子。 – 2010-04-08 04:25:26