タグ UIViewのプロパティを使用することができますと思います。
私のプログラムは、次のようなものがあります。
- (NSInteger)encodeTagForButtonID:(NSString *)buttonID;
- (NSString *)decodeButtonIDFromEncodedTag:(NSInteger)tag;
IはUIButtonを作成するときに、私はタグにボタンのIDを符号化します。 buttonIDは意味のあるものでも、定義された値のような単なる整数かもしれません。アクションの署名は次の形式になります。- (void)buttonAction:(id)sender;、タグの値をセンダーから取得できます。
編集:のUITableViewのデータソースの方法で例えば
、。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
/// new an autoreleased cell object
}
// Configure cell
cell.tag = [self encodeTagWithIndexPath:indexPath];
return cell;
}
このセルに触れると、タグからindexPathを取得します。
UIButtonはUIViewのサブクラスなので、タグもあります。たとえば、カスタムactionSheetを作成し、UIButtonsのリストを含んでいます。私がUIButtonを押し下げると、押されたボタンを知る必要があります。だから、私はタグに行情報を割り当てます。私は、ボタンをタッチすると
NSArray *buttonListInActionSheet = ....; ///< UIButton array, a button per row.
for (int idxBtn = 0; idxBtn < [buttonListInActionSheet count]; ++idxBtn) {
UIButton *btn = [buttonListInActionSheet objectAtIndex:idxBtn];
btn.tag = (100 + idxBtn);
}
、私はあなたの入力FR
- (void)buttonTouched:(id)sender {
UIButton *btn = (UIButton *)sender;
NSInteger idxBtn = (btn.tag - 100);
}
おかげで、行情報を得ることができます。私はタグを使用する方法について非常に明確ではない。あなたはタグとそれをどうやって使うのかをもっと詳しく教えてください。 –