2013-12-14 5 views
1

Я делаю простое приложение, которое включает в UITableView с пользовательской Cells, я прочитал этот учебник http://www.arcticmill.com/2012/05/uitableview-with-custom-uitableviewcell.html Все работает как шарм, но я не знаю, как добавить UITableView внутри UIView или UIScrollView, поэтому таблица не использует весь экран.UITableView внутри UIView MonoTouch

using System; 
using MonoTouch.UIKit; 
using System.Collections.Generic; 
using MonoTouch.Foundation; 
using MonoTouch.ObjCRuntime; 

namespace CustomUITableViewCellSample 
{ 
public class ListSource : UITableViewSource 
{ 
private List<string> _testData = new List<string>(); 

public ListSource() 
{ 
    _testData.Add ("Green"); 
_testData.Add ("Red"); 
_testData.Add ("Blue"); 
_testData.Add ("Yellow"); 
_testData.Add ("Purple"); 
_testData.Add ("Orange"); 
} 

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
{ 
// Reuse a cell if one exists 
CustomListCell cell = tableView.DequeueReusableCell ("ColorCell") as CustomListCell; 

if (cell == null) { 
// We have to allocate a cell 
var views = NSBundle.MainBundle.LoadNib ("CustomListCell", tableView, null); 
cell = Runtime.GetNSObject (views.ValueAt (0)) as CustomListCell; 
} 

    // This cell has been used before, so we need to update it's data 
cell.UpdateWithData (_testData [indexPath.Row]); 

return cell; 
    } 

public override int RowsInSection (UITableView tableview, int section) 
{ 
    return _testData.Count; 
} 
} 
} 

Как я могу видеть, ListSource наследует от UITableViewSource, но я действительно не имеют понятия о том, как добавить его в другой Scrollview

ответ

0

Вы бы на него с точки зрения прокрутки, как вы бы, чтобы UIViewController или UIView.

В UIViewController вы бы сказали

[self.view addSubview:tableView]; 

Для того, чтобы сделать это с целью прокрутки просто создать вид прокрутки, а затем создать экземпляр вашего специального представления таблицы и добавить его просмотра представления скроллинга , затем добавьте представление прокрутки в представление UIViewController. Вроде так:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; 

    UITableView *tableView = [[UITableView alloc] initWithFrame:scrollView.frame style:UITableViewStylePlain]; 

    [scrollView addSubview:tableView]; 

    [self.view addSubview:scrollView]; 

Вы можете делать все, что хотите, с размером рамки прокрутки и другими свойствами.

В C# вы могли бы сделать:

this.View.AddSubview (tableView); 

И:

var scrollView = new UIScrollView (view.Frame); 

    var tableView = new UITableView (scrollView.Frame, UITableViewStyle.Plain); 

    scrollView.AddSubview (tableView); 

    View.AddSubview (scrollView); 
Смежные вопросы