gpt4 book ai didi

ios - tableview 页脚中的按钮未被调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:44 24 4
gpt4 key购买 nike

我在 UIView 中声明了 UIViewUIButton

-(void)viewWillAppear:(BOOL)animated
{
footerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,300)];

UILabel *totallabel = [[UILabel alloc]initWithFrame:CGRectMake(50,5,320,40)];
totallabel.text = @"Grand Total =";
totallabel.font = [UIFont fontWithName:@"Lato-Regular" size:10];
totallabel.font = [UIFont systemFontOfSize:14];
[footerView addSubview:totallabel];
UILabel *lblRs = [[UILabel alloc]initWithFrame:CGRectMake(160,5,320,40)];
lblRs.text = @"Rs.";
lblRs.font = [UIFont fontWithName:@"Lato-Regular" size:10];
lblRs.font = [UIFont systemFontOfSize:14];
[footerView addSubview:lblRs];
totalcostlabel = [[UILabel alloc]initWithFrame:CGRectMake(190,5,320,40)];
totalcostlabel.font = [UIFont fontWithName:@"Lato-Regular" size:10];
totalcostlabel.font = [UIFont systemFontOfSize:14];
[footerView addSubview:totalcostlabel];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
aButton.frame = CGRectMake(70,50,150,40);
aButton.backgroundColor = [UIColor colorWithRed:119.0/225.0 green:49.0/255.0 blue:88.0/255.0 alpha:1.0];
[aButton setTitle:@"Checkout" forState:UIControlStateNormal];
[aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
aButton.titleLabel.font = [UIFont fontWithName:@"Lato-Regular" size:10];
[aButton addTarget:self action:@selector(btnChackOut:) forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:aButton ];

[self.tblView setTableFooterView:footerView];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return footerView;
}

- (void)btnChackOut:(UIButton *)sender {
NSLog(@"btn clicked");
}

当我点击在我的页脚中声明的 Checkout 按钮时,没有执行点击事件并且没有调用操作方法

最佳答案

我得到了解决方案,现在它已经奏效了。应用下面的代码。

在 .h 中

 #import "CustomCell.h" 

-(IBAction)actionContinue:(id)sender;

@property (strong, nonatomic) IBOutlet UITableView *tblViewCart;

.m

@synthesize tblViewCart;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
arrayImageCart = [[NSMutableArray alloc]initWithObjects:@"ios7.jpg",@"iphone_6.jpg",nil];
arrayPrice = [[NSMutableArray alloc]initWithObjects:@"Rs 60,000",@"Rs 55,000",nil];
arrayDescription = [[NSMutableArray alloc]initWithObjects:@"Made In China",@"Headquarter is in US",nil];
arrayOtherDetail = [[NSMutableArray alloc]initWithObjects:@"Black Color",@"White Color",nil];
arraySubTotal = [[NSMutableArray alloc]initWithObjects:@"Rs 60,000",@"Rs 55,000",nil];
arrayTotal = [[NSMutableArray alloc]initWithObjects:@"110000",nil];
arrayTotalCharges = [[NSMutableArray alloc]initWithObjects:@"2000",nil];
arrayYouPay = [[NSMutableArray alloc]initWithObjects:@"112000", nil];
self.tblViewCart.separatorColor = [UIColor clearColor];
}

// Button Action
-(IBAction)actionContinue:(id)sender
{


}

#pragma mark - UITableView Delegate Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 203;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(section==0)
return arrayPrice.count;
else
return arrayYouPay.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"Reuse"];
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
if(indexPath.section==0)
{
cell = [nib objectAtIndex:0];
cell.imageViewCart.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayImageCart objectAtIndex:indexPath.row]]];
cell.lblPriceDetails.text = [NSString stringWithFormat:@"%@",[arrayPrice objectAtIndex:indexPath.row]];
cell.lblDescriptionAbtProduct.text = [NSString stringWithFormat:@"%@",[arrayDescription objectAtIndex:indexPath.row]];
cell.labelOtherDetails.text = [NSString stringWithFormat:@"%@",[arrayOtherDetail objectAtIndex:indexPath.row]];
cell.lblSubTotal.text = [NSString stringWithFormat:@"%@",[arraySubTotal objectAtIndex:indexPath.row]];
}
else
{
cell = [nib objectAtIndex:1];
cell.lblTotal.text = [NSString stringWithFormat:@"%@",[arrayTotal objectAtIndex:indexPath.row]];
cell.lblTotalCharges.text = [NSString stringWithFormat:@"%@",[arrayTotalCharges objectAtIndex:indexPath.row]];
cell.lblYouPay.text = [NSString stringWithFormat:@"%@",[arrayYouPay objectAtIndex:indexPath.row]];
}
return cell;
}

通过NewFile->Source->CocoaTouchClass->Next>SubClassof:UITableViewCell,Class->CustomClass with CheckBox 创建自定义Cell 同时创建XIB文件(这是价格细节)。然后在 CustomCell.xib 文件中创建另一个 UITableViewCell 并为总金额和支付命名为 CustomCell。

关于ios - tableview 页脚中的按钮未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31578895/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com