Uitableview learning --- 1, uitableview --- 1
# Import "ViewController. h "@ interface ViewController () @ property (strong, nonatomic) NSArray * bj; @ property (strong, nonatomic) NSArray * gd; @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; self. bj = @ [@ "Dongcheng", @ "Xicheng", @ "Xuanwu", @ "Chongwen"]; self. gd = @ [@ "Guangdong", @ "Foshan", @ "Shenzhen"] ;}# data source method of pragma mark-TableView # Number of pragma mark groups-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {re Turn 2 ;}# pragma mark the number of tables displayed in each group, specifying the number of rows in each group-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {if (section = 0) {return self. bj. count;} else {return self. gd. count ;}# pragma mark the data content displayed in each table. The data source is responsible for the content. // @ Interface NSIndexPath (UITableView) // + (NSIndexPath *) indexPathForRow :( NSInteger) row inSection :( NSInteger) section; // @ property (nonatomic, readonly) NSInteger section; // @ property (nonatomic, readonly) NSInteger row; // @ end // you can use the current indexPath to determine the current row and group-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell = [[UITableViewCell all Oc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: nil]; NSString * cityName = nil; // group if (indexPath. section = 0) // group 0 {cityName = _ bj [indexPath. row];} else {cityName = _ gd [indexPath. row];} [cell. textLabel setText: cityName]; return cell;} # title of The pragma mark Group-(NSString *) tableView :( UITableView *) tableView titleForHeaderInSection :( NSInteger) section {return section = 0? @ "Beijing": @ "Guangdong" ;}# subtitle at the bottom of the pragma mark group, which is usually used to describe-(NSString *) tableView :( UITableView *) tableView titleForFooterInSection :( NSInteger) section {return section = 0? @ "Beijing has Roast Duck": @ "Guangdong has Dongguan" ;}@ end
I just got started with xcode programming. I want to learn basic operations on the table (UITableView) and provide detailed instructions. Thank you very much.
There are no more words here. Let's give LZ a brief learning process.
TableView follows two Protocols: TableViewDataSource and TableViewDelegate. The name indicates a data source and a delegate. No matter how LZ creates a table view (IB or code-only), you must set the delegate and Data Source of the table view, the classes set as table view delegation and data source must implement the methods in the preceding two protocols. Otherwise, they cannot respond to the table view delegate requests and data requests. The learning method is quite clear. Open the IDE and view the specific content of the two Protocols mentioned above (all with English comments). Just implement them in your own class. When you are familiar with the table view, you should pay attention to its parent class.
UITableView inherits from UIScrollView (rolling view). Now that you are familiar with the table view, it is no harm to be familiar with its parent view. After all, the effects of some table views (such as scrolling and refreshing) it is the method and data member that needs to use the rolling view.
Finally, the table view is an important component in the IOS system UI, and is a very important control. I wish the LZ a smooth learning process.
In iOS7, UITableViewCell with Grouped type added to UINavigation will be blank. How can I adjust it?
Cell is of no type. Only UITableView is divided into Plain and Group types, and Cell is not added to UINavigationBar, so you cannot figure out what the landlord wants to do ..