Develop Note: Objective-C
✢ Notes
After add a new Button into nib/storyboard, there are some general define ways:
define variable: Referencing Outlets connect to the ViewController.h.
@interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UIButton *firstButton; @enddefine action operation: ctrl + Button connect to the ViewController.m.
@implementation ViewController - (IBAction)firstBtnTapped:(id)sender { .... } @end
NSInteger -> Int
NSInteger number = 20; int number2 = (int)number; NSIndexPath *indexPath; int row = (int)indexPath.row;Get selected row on TableView
Implement UITableView func: didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { selectedRow = (int)indexPath.row; }
✢ Extend class UITableViewDelegate, UITableViewDataSource in UIViewController
Swift
class myViewController: UIViewcontroller { .... } extension myViewController: UITableViewDelegate, UITableViewDataSource { //Set table rows func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { .... } //Draw table cells func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { .... } .... }Objective-C
@interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> .... @end @implementation ViewController //Set table rows - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { .... } //Draw table cells - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { .... } .... @end
✢ References
- How to write the ok button action in Objective-c?
- [iOS 8] 從Objective-C到Swift : UIAlertController取代UIAlertView, UIActionSheet (含Objective-C 語法)
- 在iOS 8中使用UIAlertController
- How to convert An NSInteger to an int?
- iOS, How to find selected row Of UITableView?
- How to delete objects from NSArray through tableview in Objective C?
- How to open new view from UITableViewRow button click event?
- How To Handle Row Selection in UITableView
- Open new View Controller by clicking Cell in Table View - Swift iOS
- iOS学习之Table View的简单使用
- iOS Programming Tutorial: Create a Simple Table View App
- Swift之UITableView的使用