• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 15:53:55 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我已经在 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap