如何将NSMutableArray数据项翻转到tableview?

时间:2012-02-29 09:06:24

标签: iphone

大家好我已经实现了下面的代码,我得到的NSMutableArray项目如下所示,但当我将数组项目上传到表格视图时,它显示 ContactTesting与引导服务器。错误:未知的错误代码。 这通常意味着此进程的另一个实例已在运行或挂起在调试器中。(gdb)。所以给出解决方案,将NSMutableArray项目颠覆到iphone的tableview中。

array=[[NSMutableArray alloc]init];
for (int i=0; i<[arrStation count]; i++){
        NSString *str=[[[[[arrStation objectAtIndex:i] objectForKey:@"content"]   objectForKey:@"m:properties"] objectForKey:@"d:ContactName"] objectForKey:@"text"];
        //  NSlog(@"name is : %@",str);
        //NSLog(@"name is->>>>>>> : %@",str);
        [array addObject:str];
        NSLog(@"name is->>>>>>> : %@",array);

}


2012-02-29 14:24:20.256 ContactTesting[564:f803] name is->>>>>>> : (
    "\n        Enrico Gaetani",
    "\n        J\U00e9r\U00f4me Tredan",
    "\n        Mike Tsalidis",
    "\n        Dana Sugarman",
    "\n        Necip Ozyucel",
    "\n        Goksel Topbas",
    "\n        Nizar Abdul-Baki",
    "\n        Johannes Kanis",
    "\n        Kara Westhusing",
    "\n        Andreas Erlacher",
    "\n        Rudy Van Hoe",
    "\n        Lars Nygaard",
    "\n        Juha Karppinen",
    "\n        Ronan Geraghty",
    "\n        Luca Venturelli",

为此我实现了tableView代码,如下图所示

无法向引导服务器注册com.fitzgerald.-ContactTesting.ContactTesting。错误:未知的错误代码。 这通常意味着此进程的另一个实例已在运行或挂起在调试器中。(gdb)

  • (无效)viewDidLoad中 {

    myTableView.delegate =自我; myTableView.dataSource =自我; myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    myTableView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@“list.png”]]; myTableView.scrollEnabled = YES; array = [NSMutableArray alloc];

    [super viewDidLoad];

    [自我测试]; //在加载视图后进行任何其他设置,通常是从笔尖。 }

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 返回1;
    }

  • (NSInteger)tableView:(UITableView *)表numberOfRowsInSection:(NSInteger)section { return [数组计数]; }

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

static NSString *CellIdentifier = @"Cell";
//here you check for PreCreated cell.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

//Fill the cells...  
cell.textLabel.text = [array objectAtIndex: indexPath.row];
//yourMutableArray is Array 
return cell;

}

- (无效)测试{   // NSLog(@“&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; 233333”);

NSString *jobSearchUrlString = [NSString stringWithFormat:@"http://infra2appsmobile.cloudapp.net/Infra2Apps.svc/Contacts"];
//NSLog(@"url for new articles is = %@",jobSearchUrlString);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:jobSearchUrlString]];   

NSURLConnection *theconnection =  [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theconnection) {
    RoutData = [[NSMutableData alloc] init];
}

}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

[RoutData setLength: 0];

} - (void)connection:(NSURLConnection *)连接didReceiveData:(NSData *)数据 {     [RoutData appendData:data];

NSString *thexml = [[NSString alloc] initWithData:RoutData encoding:NSUTF8StringEncoding];

NSDictionary *dictXML= [XMLReader dictionaryForXMLString:thexml error:nil];

NSMutableArray *arrStation = [[dictXML objectForKey:@"feed"] objectForKey:@"entry"] ;//this would return the array of station dictionaries

// for(int i = 0; i&lt; [arrStation count]; i ++){ // NSLog(@“---&gt;&gt;&gt; ContactNameis:&lt;&lt;&lt; ----%@”,[[[[[[arrStation objectAtIndex:i] objectForKey:@“content”] objectForKey: @“m:properties”] objectForKey:@“d:ContactName”] objectForKey:@“text”]);

    array=[[NSMutableArray alloc]init];
    for (int i=0; i<[arrStation count]; i++){
        NSString *str=[[[[[arrStation objectAtIndex:i] objectForKey:@"content"]   objectForKey:@"m:properties"] objectForKey:@"d:ContactName"] objectForKey:@"text"];
      //  NSlog(@"name is : %@",str);
        //NSLog(@"name is->>>>>>> : %@",str);
        [array addObject:str];
        NSLog(@"name is->>>>>>> : %@",array);

               }

1 个答案:

答案 0 :(得分:1)

尝试退出并重新启动模拟器,这通常可以解决问题。如果问题仍然存在,请参阅此链接... iPhone - strange error when testing on simulator