Open Xcode as well as produce a novel Single View Application. For production name, purpose SimpleTableView as well as thus produce amount out the Organization Name as well as Company Identifier amongst your customary values. Select iPhone for Devices.
Drag a tabular array stance within the stance controller.
Connect the tabular array view's datasource as well as delegate past times right-clicking on the Table View as well as dragging from the circle to the View Controller.
First, nosotros convey to produce an array where the the information volition last coming from. Inside "ViewController.m"'s interface, add together the the line
@property (strong, nonatomic) NSArray *data;
Next, within the method viewDidLoad nosotros convey to allocate the array. This is gonna last the value of each jail cellular telephone inwards the table.
self.data = [[NSArray alloc] initWithObjects:@"Number 1",@"Number 2", @"Number3", nil];
Next, nosotros convey to add together the delegate. Change this job of code
@interface ViewController ()to
@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
Next, nosotros convey to implement the delegate methods. Add the next lines of code within the "ViewController.m"
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { furnish self.data.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"cellId"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { jail cellular telephone = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } cell.textLabel.text = [self.data objectAtIndex:indexPath.row]; furnish cell; }
Build as well as Run the project, you lot should at in i lawsuit last able to encounter a really uncomplicated tabular array view.
You tin order notice download the origin code of the SimpleTableView at my repository on bitbucket.
0 komentar:
Please comment if there are any that need to be asked.