objective c - Table view as an object in a view - how to initialize with an array of data? -
My goal is something like the "select" option in an HTML form, but now it's in my app. It is best to do this with the table view after doing research, although I have a view of the picker, but the fixed height is very large.
With the interface builder I just placed a table view on my subclass of UIViewController.
How do I view the table with options? I have seen many tutorials, but all of them are for a UITableView in the form of their class and to fill the entire screen. In my application this is a small piece of the entire form.
What is a nightmare to make a relatively simple thing like table view? It either crashes or I get a table view that covers my entire scene and is not full of anything.
Variable is the object in the Desertable Interface Builder.
After a difficult day of disappointed work, anyone got the complete work code? that would be great.
I have tried many things, but this is my current code:
@interface myView: UIViewController {NSArray * countryArray; IBOutlet UITableView * Countrytable; } @protecti (nontomic, retten) UITableView * countryTabel; @end and in my .m file
@implementation myView @ synthesis countrytable; - (zero) Load view {self.countryTable.dataSource = self; } - (zero) viewDidoad {NSArray * array = [[NSArray alloc] initWithObjects: @ "test1", @ "test2", @ "test3", zero]; Self.countryTable = array; [Array Release]; [Super viewedload]; // Setup an additional after loading the view from your nibb} - (zero) Delok {[Desertable release]; [Super DeLoc]; } #pragma mark - #pragma Icon table view data source methods - (NSInteger) table view: (UITableView *) table view numberoffers inassion: (NSInteger) section {return [self.countryTable count]; } - (UITableViewCell *) TableView: (UITableView *) Table View CellForOutPath: (NSIndexPath *) Index Path {Fixed NSString * SimpleTableIdentifier = @ "SimpleTableIdentifier"; UITableViewCell * cell = [TableView deView Re-Eligible CellWithIdentifier: SimpleTableIdentifier]; If (cell == blue) {cell = [[[UITWebWeblog ALLOC] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier] autorelease]; } NSUINATOR Row = [IndexPath line]; Cell.textLabel.text = [Countryable ObjectOutIndex: Line]; Return cell; } @end
You are on the right track if you want to use UITableViewController subclass , You will obviously have a full screen table view by default. The UIViewController subclass is the right way to go to the path of using UITableView as a subview in the UIViewController's view. Some of the things you need to address are:
1) In the UIViewControllers header file, you must & lt; UITableViewDatasource, UITableViewDelegate & gt; because your view controller is responsible for filling this implementation functionally. 2) In the viewDidLoad: , set self.contryTable.delegate = self; and self.countryTable.datasource = self; The following protocol methods are required to be implemented in the following way:
- (NSInteger) TableView: (UITableView *) table view numberoffrace ins: (NSInteger ) Section {refund countryair.count; } - (NSInteger) numberOfSectionsInTableView: (UITableView *) tableview {return1; } - (UITableViewCell *) TableView: (UITableView *) Table View CellForOutPath: (NSIndexPath *) Index Path {Fixed NSString * SimpleTableIdentifier = @ "SimpleTableIdentifier"; UITableViewCell * cell = [TableView deView Re-Eligible CellWithIdentifier: SimpleTableIdentifier]; If (cell == blue) {cell = [[[UITWebWeblog ALLOC] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier] autorelease]; } NSUINATOR Row = [IndexPath line]; Cell.textLabel.text = [CountryArtIndexAx: Line]; Return cell; }
Hope it helps.
Comments
Post a Comment