如何将 nsarray 的值转换为整数值

发布于 2024-09-10 04:35:47 字数 434 浏览 2 评论 0原文

我正在从事基于分组表视图的工作,因为我想将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别低头,皇冠会掉 2024-09-17 04:35:47

NSArray 和 NSDictionary 只能保存 Objective-C 对象。 int 不是对象。该数字可能被包装为 NSNumber。要将 NSNumber 转换回 int,请调用 -intValue

 sec = [[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"] 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 an int, call -intValue:

 sec = [[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"] 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.

泡沫很甜 2024-09-17 04:35:47

什么是例外?看来

[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"];

is causing the problem.

What is the exception? Seems that

[[rsvn_detail objectAtIndex:0] objectForKey:@"totalrecord"];

is causing the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文