Reputation: 276
I'm sitting with a issue which I can't solve in a while. I must be doing something very wrong.
I have 2 views, a UIView
and UITableView
. They're embedded with a NavigationController
.
In the second view; TableView
, I want to pass a NSInteger
back to the UIView, the first view.
I've used the solution of https://stackoverflow.com/a/19343715/3355194 but didn't work for me. It gives me a 0 value back in the UIView. In the TableView it does give me right value of numberOnSectionInTableView
.
Also tried some other solution but same result.
What I did so far.
In the TableView.h
:
@protocol senddataProtocol <NSObject>
-(void)sendBadgeIntBack:(int*)section;
@property (nonatomic, assign) id delegate;
TableView.m
:
@synthesize delegate;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
self.section = [self.tableView numberOfSections];
section = [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
NSLog(@"Number of sections: %i", section-1);
return (int)[[[UIApplication sharedApplication] scheduledLocalNotifications] count]/2;
}
-(void)viewWillDisappear:(BOOL)animated
{
[delegate sendBadgeIntBack:&(section)];
}
UIView.h
:
@property (nonatomic) int section;
UIView.m
:
It gives me a 0 value here.
-(void)sendBadgeIntBack:(int*)section
{
NSLog(@"The numbers of sections in tableView are: %i", self.section);
}
Hope you could help me find the solution. Thank you in advance.
Upvotes: 0
Views: 69
Reputation: 1742
In the TableView.h:
@protocol senddataProtocol <NSObject>
-(void)sendBadgeIntBack:(int)section_selected;
@property (nonatomic, assign) id delegate;
@property (nonatomic) int section;
TableView.m:
@synthesize delegate;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
self.section = [self.tableView numberOfSections];
section = [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
NSLog(@"Number of sections: %i", section-1);
return (int)[[[UIApplication sharedApplication] scheduledLocalNotifications] count]/2;
}
-(void)viewWillDisappear:(BOOL)animated
{
[delegate sendBadgeIntBack:section];
}
UIView.h:
@property (nonatomic) int section;
UIView.m: It gives me a 0 value here.
-(void)sendBadgeIntBack:(int*)section_selected;
{
self.section = section_selected;
NSLog(@"The numbers of sections in tableView are: %i", self.section);
}
Upvotes: 2
Reputation: 4552
You're using pass by reference (int *)
instead of pass by value (int)
which you should use for primitive values. To simplify, objects get a star, integers, floats, structs etc. don't.
Additionally, if the problem still persists, you probably didn't set your delegate properly, put a breakpoint in the method and check if it gets called properly.
Upvotes: 1