【发布时间】:2016-03-07 10:19:26
【问题描述】:
问题是我有一个带有自定义单元格的表格视图。在牢房里,我有一个按钮。单击按钮时,它应该更改表格视图之外的标签文本。
编辑: 我试图更改的标签文本在不同的视图上。 ViewController 有一个表格视图和一个标签视图。在 tableview 里面是一个按钮,当它被点击时,它会改变标签的视图文本。
CustomCell 和 TableSource:
namespace Testing.iOS
{
public partial class CustomCell : UITableViewCell
{
// Code omitted
public class TableSource : UITableViewSource
{
ViewController vc = new ViewController();
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell (CustomCell.Key) as CustomCell;
if (cell == null)
{
cell = new CustomCell ();
var views = NSBundle.MainBundle.LoadNib("CustomCell", cell, null);
cell = Runtime.GetNSObject( views.ValueAt(0) ) as CustomCell;
}
cell.btn.TouchUpInside += (object sender, EventArgs e) =>
{
// Change label that is outside tableview
vc.updateLabel();
};
// Code omitted
return cell;
}
}
}
}
视图控制器:
namespace Testing.iOS
{
public partial class ViewController : UIViewController
{
public ViewController () : base ("ViewController", null)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
tableView.RegisterNibForCellReuse (CustomCell.Nib, "CustomCell");
tableView.Source = new CustomCell.TableSource();
}
public override void DidReceiveMemoryWarning ()
{
base.DidReceiveMemoryWarning ();
}
public void updateLabel()
{
label.Text = "testing";
}
}
}
【问题讨论】:
-
那么您面临什么问题,从问题来看,更改按钮操作中的标签文本非常直接。
-
问题是:点击tableview中的按钮时,无法更改tableview之外的文本。
标签: c# ios uitableview xamarin xamarin.ios