Previous 1 2 Next 23 Replies Latest reply: Nov 23, 2008 12:04 PM by iPhil_good
.macSven Level 1 Level 1 (0 points)
In my AppDelegate.m there is a button and if I click on it, a TabBarItem should get a badge with the value "!". But it should not be the same Item like the View with the button but another TabBarItem.

How can I do this?

In the next step, I will show an alert selecting the the view with the badged Item. The alert should only be displayed if the badge has the value "!".

I hope it's not to much work!?
Thanks for helping me.

MacBook, Mac OS X (10.5.5)
  • .macSven Level 1 Level 1 (0 points)
    Okay, I figured out that you can use Numbers in a badge.
    With the following code it's possible to set the badge of the App-Icon.

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];

    If anybody hasn't an idea how I solve my first told problem, maybe you know how I get the Information of the ApplicationBadgeNumber? It would help me, if could use something like this:

    if (ApplicationBadgeValue = "1") {

    Any idea?
  • iPhil_good Level 1 Level 1 (125 points)
    Have a look at the documentation !

    Searching for "UITabBarItem" will show you there is a property called badgeValue which is a read/write NSString.

    The applicationBadgeNumber is for the icon on SpringBoard.

  • .macSven Level 1 Level 1 (0 points)
    I'am absolutly new in developing with Xcode. The documentation doesn't help me, becuase I don't understand what I have to do.

    I've tried something like this:


    It doesn't work and makes not sense to me, too. Because in the code, there isn't set the specified Item which the badge should display.

    It would help me, if you give me some code, please!?
  • iPhil_good Level 1 Level 1 (125 points)
    In a UITabBar you have an "items" property which is an NSArray of UITabBarItem.

    Knowing the index of your tab, you can access its property through this array :
    (UITabBarItem *)([self.tabBarController.items objectAtIntex:index]).badgeValue=@"!";

    You may also want to check the selectedItem property of UITabBar if it makes sense in your program.

    Is this more helpful ?
  • .macSven Level 1 Level 1 (0 points)
    Thanks, this was more helpful, yes. But it doesn't work yet.

    I have to put this code in my AppDelegate.h, right?

    @property(copy) NSArray *items;

    And then I have to sythesize "items" in my AppDelegate.m, right?

    When I do this, I get two errors:
    1. "request for member "items" in something not a structure or onion"
    2. sythesized property "items" must either be named the same as a compatible ivar or must explicitly name an ivar"
  • iPhil_good Level 1 Level 1 (125 points)
    Actually 'items' is already a property of your UITabBar instance.
    But I made a mistake in the post above considering this was a member of the UITabBarController ;-/

    What I would do is to subclass UITabBarController adding a UITabBar *tabBar member, and link the tabbar to this property in Interface Builder. Then you would be able to access the tab bar with :
    [self.tabBarController.tabBar.items objectAtIndex:index]

    and the badge with :
    ((UITabBarItem *)([self.tabBarController.tabBar.items objectAtIndex:index]).badgeValue = @"!"

    Should be better ! Sorry ...

  • .macSven Level 1 Level 1 (0 points)
    It seems to be very complicated for me. I have linked my TabBarItem (which should get my badge) to another ViewController. Isn't it possible to put the needed code in my ViewController.h /.m ?

    This would be easy I think, because later I want to get the Information if a badge is set - I will make this in my ViewController too.

    I know, it's very difficult to help me, but I'am too new in developing. Maybe everyone has solved the problem yet, but I think I need an almost ready code in this case! Sorry!
  • iPhil_good Level 1 Level 1 (125 points)
    No problem Obviously it would be easier with the code but I'm sure we can make it !

    You may assign the property from wherever you want as long as you have a 'link' to your tabitem.
    Then just assign the badgeValue property and you should be done.

  • .macSven Level 1 Level 1 (0 points)
    It's terrible, it doesn't work. I got a lot of errors - I hate it.

    Maybe you can help me in this problem:

    It's another one, but it would solve my problem too - not looking so good, but it would work.
  • iPhil_good Level 1 Level 1 (125 points)
    Would you share your AppDelegate files .h/.m by a cut'n paste inside a {code} pair ?
    Maybe we could go ahead with that ...
  • .macSven Level 1 Level 1 (0 points)
    Now I have put out all of the new code which made erros, because I'm testing some other things.

    But would you type in the right code for me if I post my .m and .h? the way it's a very long code...

    And to get the information if the badge is set, do you need my ViewController.m /.h right!? (there I have the if-clause)
  • iPhil_good Level 1 Level 1 (125 points)
    May be you could start by posting the AppDelegate.h.
    Then we'll have a better overview ...
    If it's not enough I suggest we continue by mail.
  • .macSven Level 1 Level 1 (0 points)
    Thank you so much!!!

    Here is my AppDelegate.h:

    // iDesignerAppDelegate.h
    // iDesigner
    // Created by Sven Jansen on 02.11.08.
    // Copyright _MyCompanyName_ 2008. All rights reserved.

    #import <UIKit/UIKit.h>

    @class iDesignerViewController;
    @class SubViewController;

    @interface iDesignerAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate, UITextFieldDelegate, UIActionSheetDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
    UINavigationItem *navigationItem;

    //für Bildgrößen-Tab
    IBOutlet UIView *view;
    SubViewController *svController;

    IBOutlet UITextField* pxwidth;
    IBOutlet UITextField* pxheight;
    IBOutlet UITextField* _price;
    IBOutlet UITextField* raster;
    IBOutlet UITextField* lpi;
    IBOutlet UITextField* qf;
    IBOutlet UITextField* cmwidth;
    IBOutlet UITextField* cmheight;
    IBOutlet UIButton* _button;
    IBOutlet UIBarButtonItem* _done;
    IBOutlet UILabel* info_text;

    //für Dateigröße-Tab
    IBOutlet UITextField* b_pxwidth;
    IBOutlet UITextField* b_pxheight;
    IBOutlet UITextField* datentiefe;
    IBOutlet UITextField* kompression;
    IBOutlet UITextField* kb;
    IBOutlet UITextField* mb;
    IBOutlet UIButton* datei_button;

    //für Scan: DPI-Tab
    IBOutlet UITextField* scan_sf;
    IBOutlet UITextField* scan_qf;
    IBOutlet UITextField* scan_lpi;
    IBOutlet UITextField* scan_raster;
    IBOutlet UITextField* scan_dpi;
    IBOutlet UIButton* scan_button;

    NSString *string;


    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    @property (nonatomic, copy) NSString *string;
    @property (nonatomic, retain) SubViewController *svController;
    @property (nonatomic, retain) IBOutlet UIViewController *viewController;
    @property (nonatomic, retain) IBOutlet UINavigationItem *navigationItem;
    //@property(copy) NSArray *items;

    - (void)updateString;

    //für Bildgrößen-Tab
    @property (nonatomic, retain) UIView *view;
    @property (nonatomic, retain) UITextField *pxwidth;
    @property (nonatomic, retain) UITextField *pxheight;
    @property (nonatomic, retain) UITextField *raster;
    @property (nonatomic, retain) UITextField *lpi;
    @property (nonatomic, retain) UITextField *qf;
    @property (nonatomic, retain) UITextField *cmwidth;
    @property (nonatomic, retain) UITextField *cmheight;
    @property (nonatomic, retain) UITextField *_price;
    @property (nonatomic, retain) UIButton *_button;
    @property (nonatomic, retain) UIBarButtonItem *_done;

    //für Dateigröße-Tab
    @property (nonatomic, retain) UITextField *b_pxwidth;
    @property (nonatomic, retain) UITextField *b_pxheight;
    @property (nonatomic, retain) UITextField *datentiefe;
    @property (nonatomic, retain) UITextField *kompression;
    @property (nonatomic, retain) UITextField *kb;
    @property (nonatomic, retain) UITextField *mb;
    @property (nonatomic, retain) UIButton *datei_button;

    //für Scan: DPI-Tab
    @property (nonatomic, retain) UITextField *scan_sf;
    @property (nonatomic, retain) UITextField *scan_qf;
    @property (nonatomic, retain) UITextField *scan_lpi;
    @property (nonatomic, retain) UITextField *scan_raster;
    @property (nonatomic, retain) UITextField *scan_dpi;
    @property (nonatomic, retain) UIButton *scan_button;


    Do you use iChat? I could share my screen, I think it would be the best way isn't it?
    Search for svensmacbook as an AIM-Account

    Message was edited by: .macSven
  • iPhil_good Level 1 Level 1 (125 points)
    I suggest you add an item in your iDesignerAppDelegate class :
    IBOutlet UITableBar *tabBar;

    along with the traditional @property and @synthesize.

    In IB link the new Application Delegate property to the tab bar, and now, after importing "iDesignerAppDelegate.h" in the file you want, you have access to the tab bar items wherever in your code using :
    #import "iDesignerAppDelegate.h"
    iDesignerAppDelegate *ad = (iDesignerAppDelegate *)[[UIApplication sharedApplication] delegate];
    UITabBar *tb = ad.tabBar;
    UITabBarItem *tbi = [tb.items objectForIndex:index];
    //set the badge
    tbi.badgeValue = @"!";

    I hope this will work this time
    Sorry I'm not using any instant messenger ;-/
Previous 1 2 Next