当前位置:编程学习 > wap >>

IPA支付点击任何按钮提示支付金额一样<cell重用没问题,支付流程已走通>

我根据productID从itunes获取商品信息,可我在button上点击支付的时候消息框提示支付金额都是一样的,cell重用又没问题,请高手帮忙看看。

以下是一些关键代码:
方法一:
#pragma mark -
#pragma mark SKProductsRequestDelegate Methods

// Store Kit returns a response from an SKProductsRequest.    --- store响应方法
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    
// Parse the received product info.
 //   NSArray *myProduct = response.products;
self.validProduct = nil;
int count = [response.products count];  

int i;
// Grab the first product in the array. 
for(i=0;i<count;i++)
{
self.validProduct = [response.products objectAtIndex:i];
if (self.validProduct) {
// Yes, product is available, so return values.
//次方法跳到下面方法二。
[delegate requestedProduct:self identifier:self.validProduct.productIdentifier name:self.validProduct.localizedTitle price:[self.validProduct.price stringValue] description:self.validProduct.localizedDescription];

} else {
// No, product is NOT available, so return nil values.
NSLog(@"available validProduct!!!");
[delegate requestedProduct:self identifier:nil name:nil price:nil description:nil];
}
}
}


方法二:
//购买请求,显示在iphone上的界面信息     四
#pragma mark -
#pragma mark EBPurchaseDelegate Methods

-(void) requestedProduct:(EBPurchase*)ebp identifier:(NSString*)productId name:(NSString*)productName price:(NSString*)productPrice description:(NSString*)productDescription
{
    NSLog(@"ViewController requestedProduct");

    if (productPrice != nil)
    {
     //显示在cell中的商品名
[_listData addObject:productName];  

//显示在cell中的价格<是一个button>
[_listButton addObject:productPrice];
        NSLog(@"418 _listButton is:%@",_listButton);

NSLog(@"productId is:%@,productPrice is:%@,productName is:%@,productDescription is:%@",productId,productPrice,productName,productDescription);
        // Product is available, so update button title with price.

        
    } else {
        
        [self showAlertViewShow:@"充值列表获取失败!"];
    }
    if([_listData count]>=6)    
    {
        [_productlist reloadData];
    }
if([_listButton count] >= 6)
{
[_productlist reloadData];
}
}


方法三:
//处理TableViewCell中每一行
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
static NSString *TableSampleIdentifier = @"CMainCell";
    
    cell = [tableView dequeueReusableCellWithIdentifier:
                             TableSampleIdentifier];   
// 没有重用则手动创建对象
    if (cell == nil) {
cell = [[[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:TableSampleIdentifier] autorelease];

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = [indexPath row];
        button.frame = CGRectMake(200, 5, 80, 35);
        [button setBackgroundColor:[UIColor redColor]];
        [button setTitle:[_listButton objectAtIndex:[indexPath row]]  forState:UIControlStateNormal];
        
        //_listButton 是一个全局的动态数组,此处是用于现在在button上面的值,值打印和itunes上面的一样。
        NSLog(@"285 _listButton value is:%@",_listButton);
        
        //dataRequest:方法是我客户端向服务器请求订单号的函数
        [button addTarget:self action:@selector(dataRequest:) forControlEvents:UIControlEventTouchUpInside];
        
        [cell.contentView addSubview:button];

}
    
    UIButton *btn = nil;
    for (UIView *v in cell.contentView.subviews) {
        if ([v isKindOfClass:[UIButton class]]) {
            btn = v;
            break;
        }
    }
    
    cell.textLabel.text = [_listData objectAtIndex:[indexPath row]];     

return cell;
}


方法四:

//获取订单号
- (void)dataRequest:(UIButton *)sender
{
    
   ************ 这里应该怎么处理 ???
  //  SKProduct *product = [_listButton objectAtIndex:sender.tag];

    
    
    //注释的这段我点击button提示打印价格是对的,所以从这里说明我cell重用没问题     但是apple那边提示的支付消息框总是提示支付198元
//    NSString *stringInt = [NSString stringWithFormat:@"%@",[_listButton objectAtIndex:sender.tag]];
//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
//                                                    message:stringInt
//                                                   delegate:self
//                                          cancelButtonTitle:@"确定"
//                                          otherButtonTitles:nil];
//    [alert show];

    
NSLog(@"dataRequest!!! 获取订单号");
NSString *postAddress = [NSString stringWithFormat:@"%@",@"http://pay.show.hua.com/ajax/Recharge.ashx"];
[_request setPostValue:@"CREATE" forKey:@"OPTION"];
.....

_request.tag = 22222;
[_request setDelegate:self];
[_request startAsynchronous];
}
IAP 支付 UITableViewCell UIButton --------------------编程问答-------------------- 高手们都快快现身吧,小弟感激不尽啊。 --------------------编程问答-------------------- 在线等待高人的出现。
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,