2013-11-04 2 views
1

나는 UIButton으로 사용자 정의 UITableViewCell을 생성했습니다. iOS 6에서는 항상 예상대로 동작합니다. iOS 7에서는보기가 처음으로로드 된 후 올바르게 보입니다. 그러나 어떤 TableView.ReloadData() 후에는 버튼을 터치하고 스 와이프하여 클릭 이벤트를 발생시키지 않으면 버튼의 텍스트가 사라집니다.단추가있는 사용자 지정 UITableViewCell에서 때때로 텍스트가 사라집니다. - iOS 7

당신은 설명 영화에서 동작을 볼 수 있습니다 http://youtu.be/9SrKfouah7A

ButtonCellNew.cs

using System; 
using MonoTouch.UIKit; 
using System.Drawing; 

namespace B2.Device.iOS 
{ 
    public class ButtonCellNew : UITableViewCell 
    { 
     private string _reuseIdentifier; 
     private bool _eventRegistered; 

     public Action<object, EventArgs> ButtonClickedAction; 

     public UIButton Button { get; set; } 

     public ButtonCellNew(string reuseIdentifier) : base() 
     { 
      _reuseIdentifier = reuseIdentifier; 
      Initialize(); 
     } 

     public override string ReuseIdentifier 
     { 
      get 
      { 
       return _reuseIdentifier; 
      } 
     } 

     private void Initialize() 
     { 
      // Cell 
      SelectionStyle = UITableViewCellSelectionStyle.None; 

      // Button 
      Button = new UIButton(UIButtonType.Custom); 
      Button.Frame = Bounds; 
      Button.Font = UIFont.BoldSystemFontOfSize(15); 
      Button.SetTitleColor(Colors.ButtonTitle, UIControlState.Normal); 
      Button.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; 
      ContentView.AddSubview(Button); 
     } 

     public override void PrepareForReuse() 
     { 
      base.PrepareForReuse(); 

      Button.TitleLabel.Text = string.Empty; 
     } 

     public void RegisterEvents() 
     { 
      ButtonClickedAction = null; 

      if (!_eventRegistered) 
      { 
       Button.TouchUpInside += ButtonClicked; 
       _eventRegistered = true; 
      } 
     } 

     private void ButtonClicked(object sender, EventArgs e) 
     { 
      if (ButtonClickedAction != null) 
       ButtonClickedAction(sender, e); 
     } 
    } 
} 

MyTableViewController.cs

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
{ 
    else if (indexPath.Section == (int)SupportTableViewSection.Button && indexPath.Row == (int)SupportTableViewButtonRow.Close) 
    { 
     var cell = tableView.DequeueReusableCell("buttonCell") as ButtonCellNew; 
     if (cell == null) 
      cell = new ButtonCellNew("buttonCell"); 

     cell.Button.SetTitle("Support Einstellungen schliessen", UIControlState.Normal); 
     cell.RegisterEvents(); 
     cell.ButtonClickedAction = ExitSupportSettings; 

     return cell; 
    } 
} 

답변

2

당신의 ButtonCellNew 클래스의 PrepareForReuse 방법을 제거하십시오 .

iOS 7에서도 비슷한 문제가 있었지만 완전히 제거했습니다. 셀이 DequeueReusableCell 메서드에서 반환되기 직전에 시스템에서 호출 한 것처럼 동작이 다소 변경된 것 같습니다. 분명히, "새로운"행동은 어떤 다른 시점에서도 방법을 호출하는 것을 포함합니다. 또는 ... 그것은 버그 또는 뭔가.

어쨌든 애플은 UI 관련 속성을 리셋하고 콘텐츠와 관련된 속성을 리셋하는 데 사용할 것을 제안하기 때문에 그다지 중요하지 않습니다.

Button.TitleLabel.Text = string.Empty; 
+0

감사합니다! :없이

그래서 당신은 살 수있다 그 트릭을 ... – dannyyy

관련 문제