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;  
      @end
      
    • define 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

results matching ""

    No results matching ""