2012-03-13 97 views
0

第一个问题: 我有一个自定义TableViewCell与一个标签和两个按钮在其中。与UIButton和UILabel自定义TableView单元格

public override void ViewDidLoad() 
{ 
    base.ViewDidLoad();  
    this.btnChecked.TouchUpInside+= HandleBtnCheckedhandleTouchUpInside; 
    this.btnNotChecked.TouchUpInside += HandleBtnNotCheckedhandleTouchUpInside; 
} 

而且这里的活动

void HandleBtnNotCheckedhandleTapGestureRecognizerDelegateTouchUpInside (object sender, EventArgs e) 
    { 
     Console.WriteLine("ButtonClicked"); 
    } 

但是,如果我在UITableCell在UIButton的点击我的事件不需额外得到提升。

第二个问题:如何在代码后面更改UILabel的FontSize?

回答

1

你为什么不去做这样的:

this.btnChecked.TouchUpInside += (sender, e) => 
{ 
    HandleButtonMethod(); 
}; 

void HandleButtonMethod() 
{ 
    Console.WriteLine("ButtonClicked"); 
} 

要更改喜欢一个拉布勒的做这样的事情:

label.Font = UIFont.FromName("Arial", 20); 
+0

好的改变标签字体现在工作,但事件不起作用。 – Alex 2012-03-13 11:30:24

+0

你是如何将按钮放入单元格的?你把它添加为一个子视图?尝试这样做:在GetCell去和配置像cell.ContentView.AddSubview(controller.yourbutton) – alecnash 2012-03-13 11:38:38

+0

我在界面生成器中构建它像这个教程:http://blog.theunical.com/databases/mysql/simon-says -monotouch-lets-build-a-custom-uitableviewcell/ – Alex 2012-03-13 11:47:01

0

我找到了解决办法。但我不认为它很好。

我已经做了CustomTableCell类

public partial class CSTableCell : UIViewController 

在我的DataSource类我重写GetCell()方法

 if(cell == null) 
     { 
      cellController = new CSTableCell(); 
      NSBundle.MainBundle.LoadNib("CSTableCell", cellController, null); 
      cell = cellController.Cell; 
      cell.Tag = Environment.TickCount; 
      _controllers.Add(cell.Tag, cellController); 
     } 
     else 
     { 
      cellController = _controllers[cell.Tag]; 
     } 

     cellController.FontSize = _fontSize; 
     cellController.Text = _items[indexPath.Row]; 

     cellController.BtnChecked.TouchUpInside+=(s,e)=> 
     { 
      Console.WriteLine("Touched"); 
     }; 

现在我TouchUpInsideEvent作品。

但我不确定这是否是一个好的解决方案。为什么这个事件在我的TableCell类中不起作用?

相关问题