Objective-C:如何从两个 NSInteger 生成一个唯一的 NSInteger? [英] Objective-C: How to generate one unique NSInteger from two NSIntegers?

查看:25
本文介绍了Objective-C:如何从两个 NSInteger 生成一个唯一的 NSInteger?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
将两个整数作为一个整数传递

这会在 Objective-C 中工作吗?将两个整数作为一个整数传递

Will this work in Objective-C? Pass two integers as one integer

如果是这样,我该如何使用 NSInteger 来实现?

If so, how do I do it with NSInteger?

我之所以这么问是因为我想从 NSUIntegerrow & 计算一个唯一的 NSInteger 标签UITableViewsection?

I'm asking because I want to calculate a unique NSInteger tag from the NSUIntegers row & section of a UITableView?

看,我正在处理一个 UITableViewController,它包含三个部分,每个部分都有多行.每行都有一个 UISwitch,每个 UISwitch 都链接到相同的目标操作方法,switchAction:.

See, I'm dealing with a UITableViewController that has three sections, which each have multiple rows. Every row has a UISwitch, and each UISwitch is linked to the same target-action method, switchAction:.

switchAction:中,我的计划是检查sendertag以找出UISwitchUITableViewNSIndexPath (section & row).

In switchAction:, my plan is to inspect the sender's tag to figure out the UISwitch's NSIndexPath (section & row) of the UITableView.

所以,我想要两种方法:

So, I want two methods like:

+ (NSInteger)integerFromInteger1:(NSInteger)int1 integer2:(NSInteger)int2;
+ (NSIndexPath *)indexPathFromInteger:(NSInteger)integer;

第一种方法用 C 编写可能效果更好.如果您愿意,也可以.

The first method may work better written in C. That works too if you prefer.

推荐答案

基于 @benzado 的答案,我想出了一个很好的解决方案,用于获取发送 UISwitch 的索引路径>switchAction: 消息.

Based on @benzado's answer, I came up with a beautiful solution for how to get the index path of the UISwitch that sent the switchAction: message.

- (void)switchAction:(id)sender {
    UISwitch *onOff = (UISwitch *)sender;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:
                              (UITableViewCell *)[onOff superview]];
    // carry on...
}

不需要标签.保持你的裤子.

No tags necessary. Just keep your pants on.

这篇关于Objective-C:如何从两个 NSInteger 生成一个唯一的 NSInteger?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆