【发布时间】:2012-09-25 05:21:09
【问题描述】:
我对从 WCF 服务获得的内容进行了 XML 解析。我使用NSXMLParser 将数据加载到NSMutableArray。现在我希望将数据加载到UIView 的tableview 中。但我可以看到正在加载的空表视图和数据没有。无法理解我哪里出错了。
我的NSMutableArray是这样的:
(
{
UserName="Roy";
Password="126";
},
{
UserName="Joy";
Password="123";
},
{
UserName="Rony";
Password="5983";
}
-------------
-------------
)
UItableView 的代码是:
@interface RootViewController : UIViewController<NSXMLParserDelegate,UITableViewDataSource,UITableViewDelegate>
{
NSMutableArray *arr;
UITableView *tableView;
}
- (void)viewDidLoad
{
UITableView* tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
NSString *tempstring=[arr objectAtIndex:indexPath.row];
cell.textLabel.text= tempstring;
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
我得到一些空行的空表视图。我该如何解决这个问题?
【问题讨论】:
-
你分配数组了吗
-
是的,我在 load() arr=[[NSMutableArray alloc] init];
-
然后尝试通过设置断点来初始化你的数组,它是否携带值。如果是,请检查它崩溃的位置。
-
是的,向 numberOfRows 添加断点以检查数组是否是您认为的那样。类似的东西。
-
是的,它正在初始化并且我正在获取值。但是不能将断点输入 TableView
标签: iphone uitableview xcode4