OGeek|极客世界-中国程序员成长平台

标题: ios - 未调用 tableview 页脚中的按钮 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:53
标题: ios - 未调用 tableview 页脚中的按钮

我已经在 UIView

中声明了 UIViewUIButton
-(void)viewWillAppearBOOL)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 actionselector(btnChackOut forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:aButton ];

    [self.tblView setTableFooterView:footerView];
}

- (UIView *)tableViewUITableView *)tableView viewForFooterInSectionNSInteger)section
{
    return footerView;
}

- (void)btnChackOutUIButton *)sender {
    NSLog(@"btn clicked");
}

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



Best Answer-推荐答案


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

在.h中

 #import "CustomCell.h" 

-(IBAction)actionContinueid)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)actionContinueid)sender
 {


 }

#pragma mark - UITableView Delegate Methods
-(NSInteger)numberOfSectionsInTableViewUITableView *)tableView
{
    return 2;
}
-(CGFloat)tableViewUITableView *)tableView heightForRowAtIndexPathNSIndexPath *)indexPath
{
    return 203;
}
-(NSInteger)tableViewUITableView *)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 和 CheckBox 创建自定义单元 也创建 XIB 文件(这是价格详情)。 然后在 CustomCell.xib 文件中创建另一个 UITableViewCell 并为 Total Amount 和 Pay 命名为 CustomCell。

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4