如何将 nsarray 的值转换为整数值
我正在从事基于分组表视图的工作,因为我想将 NSarray 的值转换为整数以指定 numberOfRowsInSection 的部分值,但它引发了对以下代码的期望。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int sec;
if (section == 0){ sec=6; }
else if(section == 1){ sec=6; }
else if(section == 2){
sec=[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"];
}
return sec;
}
任何人都可以帮助提前纠正它,感谢您的建议
问候, 萨蒂什
I working on grouped table view based work in that in that i want to convert the value of NSarray into integer for specifing to section value of numberOfRowsInSection but it throws expection on putting following code.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int sec;
if (section == 0){ sec=6; }
else if(section == 1){ sec=6; }
else if(section == 2){
sec=[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"];
}
return sec;
}
Anybody help to recify it advance thanks for your suggestion
Regards,
sathish
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSArray 和 NSDictionary 只能保存 Objective-C 对象。
int
不是对象。该数字可能被包装为 NSNumber。要将 NSNumber 转换回int
,请调用-intValue
:当然,请确保
rsvn_detail
确实是 NSDictionary 的 NSArray。如果没有-intValue
不会导致异常,只会引发编译器警告/错误。NSArray and NSDictionary can only hold Objective-C objects. An
int
is not an object. It is likely the number is wrapped as an NSNumber. To convert an NSNumber back to anint
, call-intValue
:Of course, make sure
rsvn_detail
is really an NSArray of NSDictionary. Without-intValue
won't cause exceptions, only compiler warning/error will be raised.什么是例外?看来
is causing the problem.
What is the exception? Seems that
is causing the problem.