开发者

Why I can't put [a objectAtIndex:indexPath.row] at NSString

开发者 https://www.devze.com 2023-02-20 09:30 出处:网络
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *selectedFriend = [friends objectAtIndex:indexPath.row];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedFriend = [friends objectAtIndex:indexPath.row];
//selectedFriend invalid summary
//Initialize the detail view controller and display it.
LeaveMViewController *LMController = [[LeaveMViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
LMController.whosmess = selectedFriend;
[LMController release];
LMController = nil;

please help

NSMutableArray *friends;
NSMutableDictionary *listofFriends;


 - (void) parseXMLFileAtURL:(NSString *) URL{   
friends = [[NSMutableArray alloc] init];

NSURL *xmlURL = [NSURL URLWithString:URL];  
friendsParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[friendsParser setDelegate:self];
[friendsParser setShouldProcessNamespaces:NO];
[friendsParser setShouldReportNamespacePrefixes:NO];
[friendsParser setShouldResolveExternalEntities:NO];

[friendsParser parse];

}

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed        from web site (Error code %i )", [parseError code]];
NSLog(@"error parsing XML: %@", errorString);

UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
   }

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName   namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{          
if ([elementName isEqualToString:@"Friend"]){
    listOfFriends = [[NSMutableDictionary alloc] init];
    [listOfFriends setObject:[attributeDict objectForKey:@"firstname"] forKey:@"firstname"];
    [listOfFriends setObject:[attributeDict objectForKey:@"user_id"] forKey:@"user_id"];        
    [friends addObject:[listOfFriends copy]];   
}

    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyIdentifier = @"MyIdentifie开发者_C百科r";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}

// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
[cell setText:[NSString stringWithFormat:@"%@, %@",[[friends objectAtIndex: storyIndex] objectForKey: @"firstname"],[[friends objectAtIndex: storyIndex] objectForKey: @"user_id"]]];
return cell;
    }

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedFriend = @"hui";
who=[[NSString alloc] initWithFormat:@"ai bliat %&",[friends objectAtIndex:indexPath.row]];
// NSString *selectedFriend = [friends objectAtIndex:indexPath.row];
LeaveMViewController *LMController = [[LeaveMViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
LMController.whosmess = selectedFriend;
[LMController release];
LMController = nil;

}


problem solved

NSString *selectedFriend = [friends objectAtIndex:indexPath.row];

was replaced by

int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *selectedFriend =[NSString initWithFormat @"%@", [[friends objectAtIndex: storyIndex] objectForKey: @"firstname"]];
0

精彩评论

暂无评论...
验证码 换一张
取 消