Objective-C: The Right Passing Method

How can you pass a variable among methods?

I have one UITabBarController.

- (void)tabBarController:(UITabBarController *)tabBarController 
        didSelectViewController:(UIViewController *)viewController {
     NSLog(@"my ns string %@", viewController.tabBarItem.title);
}

I need an NSString variable so that I can access it when table cells are specified in this event. The idea is that the contents of the table depend on the name of the tab.

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath

In other languages โ€‹โ€‹that I'm familiar with, I always just pass variables among functions or they are variables inside a class. I'm new to Objective-C, and I'm not sure how to handle variable areas.

I read that this can be done by creating a class that is used exclusively for variables. Is this the right way to do this? Advice is welcome.

+5
source share
5

Objective-C - , , .

, .

, - , , , .

0

Objective-C . , .

iphone , , .

, . () , , , .

, , .

0

. / .

, , ,

NSString *title = self.tabbarItem.title;  
0

, .

. , :

//In some place or your UITabBarController
...
UITabBarItem *item;
...
item.tag = YOUR_DEFINED_VALUE;
...


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
     switch(tabBarController.tabBar.selectedItem.tag) {
case YOUR_DEFINED_VALUE:
...
self.typeOfCell = CELL_TYPE;
[tableView reloadData];
...
}
}

UITabBarItem UIBarItem, 'tag'.

0

, . : @property .

ex: -

- viewController, ,

@property(nonatomic, retain) NSString *someValue;

,

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
     viewController.someValue = someValues;
}

viewController ,

NSLog(@"value is %@", self.someValue);

self.tabbarItem.title cellForRowAtIndexPath:.

0

All Articles