Objective c 应用程序内购买-如何制作;是”;按钮是;“购买”;

Objective c 应用程序内购买-如何制作;是”;按钮是;“购买”;,objective-c,tags,uibutton,in-app-purchase,uialertview,Objective C,Tags,Uibutton,In App Purchase,Uialertview,我想将UIAlertView中的“是”按钮重命名为“购买” 这里是代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; SKProd

我想将
UIAlertView
中的“是”按钮重命名为“购买”

这里是代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

SKProduct * product = (SKProduct *) _products[indexPath.row];
cell.textLabel.text = product.localizedTitle;


[_priceFormatter setLocale:product.priceLocale];
cell.detailTextLabel.text = [_priceFormatter stringFromNumber:product.price];

if ([[RageIAPHelper sharedInstance] productPurchased:product.productIdentifier]) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    cell.accessoryView = nil;
} else {
    UIButton * buyButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    buyButton.frame = CGRectMake(0, 0, 72, 37);
    [buyButton setTitle:@"Buy" forState:UIControlStateNormal];
    buyButton.tag = indexPath.row;
    [buyButton addTarget:self action:@selector(buyButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.accessoryView = buyButton;
}

return cell;
}


- (void)buyButtonTapped:(id)sender {

UIButton * buyButton = (UIButton *)sender;
SKProduct *product = _products[buyButton.tag];

NSLog(@"Buying %@...", product.productIdentifier);
[[RageIAPHelper sharedInstance] buyProduct:product];

}
到目前为止,单元格中的“购买”操作确实有效。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];

if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
    UIStoryboard    *   storyboard  =   [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    SSDetailViewController * detailViewController   =   [storyboard instantiateViewControllerWithIdentifier:@"detail"];
    [self.navigationController pushViewController:detailViewController animated:YES];
} else {
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Cell Selected to Buy"
                                                         message:@"Tap \"YES\" to Confirm Purchase"
                                                        delegate:self
                                               cancelButtonTitle:@"Cancel"
                                               otherButtonTitles:@"Yes", nil];
    [alertView show];


}
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

if (buttonIndex == 0) {
    NSLog(@"cancel");
} else {
    NSLog(@"YES");

 // **here want to make "buy" operation, but how to get `button.tag` that in the tapped cell?**      
 //SKProduct *product = _products[button.tag];
 //[[RageIAPHelper sharedInstance] buyProduct:product];
}
}
这里有两张图片供参考,谢谢任何能帮我的人


UIView的标记不适合传递信息,尽管您经常看到这种滥用


保存所选单元格的索引路径,并在触发警报按钮时使用该路径。按钮上的名称并不重要,只需给它另一个标题。

为什么不简单地更改传递给按钮标题的字符串?@rmaddy,如果您查看源代码中的注释,很明显,OP的目的是确定按下了哪个单元格。他似乎认为重命名会对他有所帮助。好的,问题是关于更改标签,但代码中的注释是关于确定选择了哪个产品。@rmaddy,我想,OP假设按钮的相同标题将导致相同的对象?他没有真的说,他想给它改名。他“希望它是……”。所以不是很清楚,当然也缺乏对OOP和视图层次结构的理解。嗨,伙计们,实际上我在学习IAP,参考这个示例,所以我在这里放的大多数代码都是从这个示例中得到的。关于您评论的标记问题,我不是很清楚,只是利用示例代码将教程向前推进到我假设的函数。最后,如果你能就我想做的事提出建议,我将不胜感激。这是一篇关于标签滥用的好文章:谢谢你在我的上述评论中没有提到的关于标签滥用的观点。在这种情况下,修改并继续实现我的想法的正确方法是什么?正如我所说的:在
tableView:didSelectRowWithIndexPath:
中保存所选索引路径,并在UIAlertView的委托方法中使用它。标签永远不会有用。在5年的专业可可开发中,我没有使用过一次。