Reputation: 11753
In order to get the trash image displayed in a standard toolbar on iOS. I am using the following code:
UIBarButtonItem *tempTBButn=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:nil action:nil];
UIImage *trashImg=tempTBButn.image;
But it does not work. The result I get in trashImg is just nil. What should I do to obtain the result I want? That is to have the trash icon in trashImg.
Upvotes: 1
Views: 379
Reputation: 13549
The image property is only set when you create a UIBarButtonItem
with one of the custom image init methods like:
UIBarButtonItem *customImageBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"yourImage"] style:UIBarButtonItemStylePlain target:self action:@selector(barButtonItemPressed:)];
The image property defaults to nil when you use the initWithBarButtonSystemItem:
method. Your best bet is to just use a trash icon of your own, or work with just having the standard icon on the nav.
Upvotes: 1