I'm creating my own annotation callout by subclassing MKPinAnnotationView. Everything works great, except for when I try to add buttons inside the new callout... the buttons are never called on touch... any idea why?
Thanks in advance!
Code is below:
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self) {
self.frame = CGRectMake(0.0f, 0.0f, 284.0f, 245.0f);
self.backgroundColor = [UIColor clearColor];
UIImageView *callout_bkg = [[UIImageView alloc] init];
callout_bkg.image = [UIImage imageNamed:#"callout_bkg.png"];
callout_bkg.frame = CGRectMake(0, 0, 240, 110);
[self addSubview:callout_bkg];
titleLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 8.0f, 145.0f, 20.0f)];
titleLabel_.textColor = [UIColor whiteColor];
titleLabel_.textAlignment = UITextAlignmentLeft;
titleLabel_.backgroundColor = [UIColor clearColor];
titleLabel_.font = [UIFont fontWithName:#"Geogrotesque" size:12];
[self addSubview:titleLabel_];
descLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 30.0f, 180.0f, 40.0f)];
descLabel_.textColor = [UIColor grayColor];
descLabel_.textAlignment = UITextAlignmentLeft;
descLabel_.backgroundColor = [UIColor clearColor];
descLabel_.numberOfLines = 15;
descLabel_.font = [UIFont fontWithName:#"Geogrotesque" size:10];
[self addSubview:descLabel_];
communityLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(125.0f, 8.0f, 60.0f, 20.0f)];
communityLabel_.textColor = [UIColor whiteColor];
communityLabel_.textAlignment = UITextAlignmentRight;
communityLabel_.backgroundColor = [UIColor clearColor];
communityLabel_.font = [UIFont fontWithName:#"Geogrotesque" size:10];
[self addSubview:communityLabel_];
typeLabel_ = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 72.0f, 50.0f, 20.0f)];
typeLabel_.textColor = [UIColor whiteColor];
typeLabel_.textAlignment = UITextAlignmentLeft;
typeLabel_.backgroundColor = [UIColor clearColor];
typeLabel_.font = [UIFont fontWithName:#"Geogrotesque" size:10];
[self addSubview:typeLabel_];
facebook_share = [[UIButton alloc] initWithFrame:CGRectMake(200, 17, 29, 27)];
facebook_share.backgroundColor = [UIColor clearColor];
[facebook_share setBackgroundImage:[UIImage imageNamed:#"btn_annotation_share_fb.png"] forState:UIControlStateNormal];
[facebook_share addTarget:self action:#selector(calloutAccessoryTapped) forControlEvents:UIControlStateNormal];
[self addSubview:facebook_share];
twitter_share = [[UIButton alloc] initWithFrame:CGRectMake(200, 44, 29, 28)];
twitter_share.backgroundColor = [UIColor clearColor];
[twitter_share setBackgroundImage:[UIImage imageNamed:#"btn_annotation_share_twitter.png"] forState:UIControlStateNormal];
[twitter_share addTarget:self action:#selector(calloutAccessoryTapped) forControlEvents:UIControlStateNormal];
[self addSubview:twitter_share];
}
return self;
}
-(void)calloutAccessoryTapped {
NSLog(#"TEST!");
}
- (void)dealloc {
[facebook_share release];
[twitter_share release];
[community_ release], community_ = nil;
[communityLabel_ release], communityLabel_ = nil;
[type_ release], type_ = nil;
[typeLabel_ release], typeLabel_ = nil;
[desc_ release], desc_ = nil;
[descLabel_ release], descLabel_ = nil;
[title_ release], title_ = nil;
[titleLabel_ release], titleLabel_ = nil;
[super dealloc];
}
-(void)drawRect:(CGRect)rect {
[super drawRect:rect];
titleLabel_.text = self.type;
descLabel_.text = self.desc;
communityLabel_.text = self.community;
typeLabel_.text = self.title;
[facebook_share addTarget:self action:#selector(test:) forControlEvents:UIControlStateNormal];
}
try with :
facebook_share = [UIButton buttonWithType:UIButtonTypeCustom];
facebook_share.frame = yourFrame;
Related
How do I make UINavigationBar title to be user editable, I've tried setting the titleView to be a textfield however it doesn't look the same.. It's missing that outline or drop shadow. I'm aiming for it to look like the default one.
This is what i'm implementing at the moment:
_titleField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 200, 26)];
[_titleField setDelegate:self];
_titleField.text = _bugDoc.data.title;
_titleField.font = [UIFont boldSystemFontOfSize:20];
_titleField.textColor = [UIColor whiteColor];
_titleField.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = _titleField;
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadTitle];
}
- (void)loadTitle
{
txtField_navTitle = [[UITextField alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x,7,self.view.bounds.size.width,31)];
txtField_navTitle.delegate = self;
[txtField_navTitle setBackgroundColor:[UIColor clearColor]];
txtField_navTitle.textColor = [UIColor whiteColor];
txtField_navTitle.textAlignment = UITextAlignmentCenter;
txtField_navTitle.borderStyle = UITextBorderStyleNone;
txtField_navTitle.font = [UIFont boldSystemFontOfSize:20];
txtField_navTitle.autocorrectionType = UITextAutocorrectionTypeNo;
txtField_navTitle.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.navigationItem setTitleView:txtField_navTitle];
txtField_navTitle.layer.masksToBounds = NO;
txtField_navTitle.layer.shadowColor = [UIColor whiteColor].CGColor;
txtField_navTitle.layer.shadowOpacity = 0;
[txtField_navTitle release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
self.title = textField.text;
return YES;
}
Please dont forget to #import <QuartzCore/QuartzCore.h>
Try this way this works for me.
// Custom Navigation Title.
UILabel* tlabel=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 300, 40)];
tlabel.text=self.title;
tlabel.textAlignment=NSTextAlignmentCenter;
tlabel.font = [UIFont boldSystemFontOfSize:17.0];
tlabel.textColor=[UIColor colorWithRed:7.0/255.0 green:26.0/255.0 blue:66.0/255.0 alpha:1.0];
tlabel.backgroundColor =[UIColor clearColor];
tlabel.adjustsFontSizeToFitWidth=YES;
self.navigationItem.titleView=tlabel;
I'm having a problem with some code in the loadView: method of one of my view controllers. Essentially I have a view which centres itself in a larger view (on an iPad) and has some labels, buttons and icons which are programmatically loaded into it.
The problem occurs when the view controller calls the dealloc method, and tries to release. I get a -[CALayer release]: message sent to deallocated instance error and the application crashes.
From reading up about this error, it appears I am over-releasing something, but I don't think that's the case: the code below is the trouble maker and I've tried both autorelease and manual release calls on everything, as well as simply not releasing them (I know, I know, that's bad) but it continues to cause havok.
container = [[UIView alloc] initWithFrame:CGRectNull];
container.autoresizingMask = ( UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin );
container.frame = CGRectMake( (viewSize.width-320)/2, (viewSize.height-480)/2, 320, 480);
[self.view addSubview:container];
UILabel *welcomeTo = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
welcomeTo.backgroundColor = [UIColor clearColor];
welcomeTo.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:18.0];
welcomeTo.frame = CGRectMake(23, 15, 103, 24);
welcomeTo.shadowColor = [UIColor blackColor];
welcomeTo.shadowOffset = CGSizeMake( 0, 1 );
welcomeTo.text = #"Welcome to";
welcomeTo.textAlignment = UITextAlignmentLeft;
welcomeTo.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:welcomeTo];
UILabel *progressions = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
progressions.backgroundColor = [UIColor clearColor];
progressions.font = [UIFont fontWithName:#"HelveticaNeue-BoldItalic" size:44.0];
progressions.frame = CGRectMake(20, 30, 280, 56);
progressions.shadowColor = [UIColor blackColor];
progressions.shadowOffset = CGSizeMake( 0, 1 );
progressions.text = #"Progressions";
progressions.textAlignment = UITextAlignmentCenter;
progressions.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:progressions];
UILabel *blurb = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
blurb.backgroundColor = [UIColor clearColor];
blurb.font = [UIFont fontWithName:#"HelveticaNeue" size:14.0];
blurb.frame = CGRectMake(23, 100, 274, 51);
blurb.numberOfLines = 3;
blurb.shadowColor = [UIColor blackColor];
blurb.shadowOffset = CGSizeMake( 0, 1 );
blurb.text = #"Kick off the fun by adding some content, or if you're not sure what you're doing, check out the \"Getting Started\" guide!";
blurb.textAlignment = UITextAlignmentLeft;
blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:blurb];
UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(20, 170, 280, 88)];
[button1 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button1 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button1 addTarget:self action:#selector(createChart:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button1];
[button1 release];
UIImageView *icon1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"addchart.png"]];
icon1.frame = CGRectMake(30, 180, icon1.frame.size.width, icon1.frame.size.height);
[container addSubview:icon1];
[icon1 release];
UILabel *button1title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 185, 180, 20)] autorelease];
button1title.backgroundColor = [UIColor clearColor];
button1title.font = [UIFont boldSystemFontOfSize:17.0];
button1title.shadowColor = [UIColor blackColor];
button1title.shadowOffset = CGSizeMake( 0, 1 );
button1title.text = #"Create a Chart";
button1title.textAlignment = UITextAlignmentLeft;
button1title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1title];
UILabel *button1blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 205, 180, 40)] autorelease];
button1blurb.backgroundColor = [UIColor clearColor];
button1blurb.font = [UIFont systemFontOfSize:13.0];
button1blurb.numberOfLines = 2;
button1blurb.shadowColor = [UIColor blackColor];
button1blurb.shadowOffset = CGSizeMake( 0, 1 );
button1blurb.text = #"A cheat sheet for a displaying a song in any key.";
button1blurb.textAlignment = UITextAlignmentLeft;
button1blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button1blurb];
UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(20, 270, 280, 88)];
[button2 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLarge.png"] forState:UIControlStateNormal];
[button2 setBackgroundImage:[UIImage imageNamed:#"emptyButtonLargeHighlighted.png"] forState:UIControlStateHighlighted];
[button2 addTarget:self action:#selector(createSet:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button2];
[button2 release];
UIImageView *icon2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"addset.png"]];
icon2.frame = CGRectMake(30, 280, icon2.frame.size.width, icon2.frame.size.height);
[container addSubview:icon2];
[icon2 release];
UILabel *button2title = [[[UILabel alloc] initWithFrame:CGRectMake(110, 285, 180, 20)] autorelease];
button2title.backgroundColor = [UIColor clearColor];
button2title.font = [UIFont boldSystemFontOfSize:17.0];
button2title.shadowColor = [UIColor blackColor];
button2title.shadowOffset = CGSizeMake( 0, 1 );
button2title.text = #"Create a Set";
button2title.textAlignment = UITextAlignmentLeft;
button2title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2title];
UILabel *button2blurb = [[[UILabel alloc] initWithFrame:CGRectMake(110, 305, 180, 40)] autorelease];
button2blurb.backgroundColor = [UIColor clearColor];
button2blurb.font = [UIFont systemFontOfSize:13.0];
button2blurb.numberOfLines = 2;
button2blurb.shadowColor = [UIColor blackColor];
button2blurb.shadowOffset = CGSizeMake( 0, 1 );
button2blurb.text = #"A collection of charts that can be displayed like a book.";
button2blurb.textAlignment = UITextAlignmentLeft;
button2blurb.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button2blurb];
UIButton *button3 = [[UIButton alloc] initWithFrame:CGRectMake(20, 370, 280, 40)];
[button3 setBackgroundImage:[UIImage imageNamed:#"emptyButtonSmall.png"] forState:UIControlStateNormal];
[button3 setBackgroundImage:[UIImage imageNamed:#"emptyButtonSmallHighlighted.png"] forState:UIControlStateHighlighted];
[button3 addTarget:self action:#selector(gettingStarted:) forControlEvents:UIControlEventTouchUpInside];
[container addSubview:button3];
[button3 release];
UILabel *button3title = [[[UILabel alloc] initWithFrame:CGRectMake(20, 370, 280, 36)] autorelease];
button3title.backgroundColor = [UIColor clearColor];
button3title.font = [UIFont boldSystemFontOfSize:17.0];
button3title.shadowColor = [UIColor blackColor];
button3title.shadowOffset = CGSizeMake( 0, 1 );
button3title.text = #"Getting Started";
button3title.textAlignment = UITextAlignmentCenter;
button3title.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:button3title];
UILabel *version = [[[UILabel alloc] initWithFrame:CGRectMake(20, 420, 280, 20)] autorelease];
version.backgroundColor = [UIColor clearColor];
version.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:12.0];
version.shadowColor = [UIColor blackColor];
version.shadowOffset = CGSizeMake( 0, 1 );
version.text = [NSString stringWithFormat:#"Version v%# (%#)", [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleVersion"], kRevisionNumber];
version.textAlignment = UITextAlignmentCenter;
version.textColor = [UIColor colorWithWhite:1.0 alpha:0.6];
[container addSubview:version];
The container property is released in the dealloc method, as follows:
- (void)dealloc {
[leather release];
[backButton release];
[container release];
[super dealloc];
}
Any answers or suggestions people can provide would be greatly appreciated! I am truly stumped.
Profile your application in the simulator with 'Zombies' Instrument.
Run your app for a while and do whatever you have to do to make your app crash. When it does, you will get a pop up like the image below and it will halt the profiling of the app:
Then if you click on the little arrow next to the address (0x158b3c00) .. it will take you to the object retain/release history for the object that was over released (the zombie).
If you highlight the line above where the retain count went to -1, and open View -> Extended detail, it should point you to the stack trace and line in your code where the object was overreleased:
If you double click the class where it is occuring, it will open up your source and show you the bad line of code:
The over-releasing could be occurring during the objects life time and not just when they're being created. A few tips:
use accessors to ensure that pointers are set to nil
be consistent with your use of release/autorelease. Personally I prefer to have [[[Class alloc] init] autorelease] all on 1 line.
Learn the difference between release/autorelease. Let's Build NSAutoreleasePool is a good place to start.
How does one create a dynamic thumbnail grid?
How is a grid created with thumbnails of images like the photo app on iphone?
How are these spaces arranged dynamically? e.g. adding and removing thumbnails.
this is my simple grid view app
- (void)viewDidAppear:(BOOL)animated {
[[Grid_ViewAppDelegate sharedAppDelegate] hideLoadingView];
temp = temp+1;
if (temp ==1){
NSLog(#"temp:%d",temp);
int n = 20; //Numbers of array;
NSArray *t = [[NSArray alloc] initWithObjects:#"calpie.gif",#"chrysler_electric.png",#"chrysler_fiat_cap.gif",#"cleanup.gif",#"ecylindri.gif",#"elect08.png",#"globe.gif",#"heat.gif",#"insur.gif"
,#"jobs.gif",#"office.gif",#"opec1.gif",#"orng_cap.gif",#"poll.gif",#"pollen.gif",#"purbar.gif",#"robinson.gif",#"robslink_cap.gif",#"scot_cap.gif",#"shoes.gif",nil];
myScrollView.contentSize = CGSizeMake(320, 460+n*2);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 1;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
NSString *mxiURL = #"http://meta-x.com/biflash/images/";
int i =0,i1=0;
while(i<n){
int yy = 4 +i1*79;
for(int j=0; j<4;j++){
if (i>=n) break;
CGRect rect;
rect = CGRectMake(4+79*j, yy, 75, 75);
UIButton *button=[[UIButton alloc] initWithFrame:rect];
[button setFrame:rect];
NSString *nn = [mxiURL stringByAppendingString:[t objectAtIndex:i]];
UIImage *buttonImageNormal=[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: nn]]];
[button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
button.tag =i;
[button addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside ];
//[self.view addSubview:button];
[myScrollView addSubview:button];
//[buttonImageNormal release];
[button release];
i++;
//
}
i1 = i1+1;
//i=i+4;
}
}
}
in AppDelegate
+ (Grid_ViewAppDelegate *)sharedAppDelegate
{
return (Grid_ViewAppDelegate *)[UIApplication sharedApplication].delegate;
}
- (void)showLoadingView
{
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor grayColor];
loadingView.alpha = 0.5;
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(142.0, 222.0, 37.0, 37.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loadingView addSubview:spinningWheel];
[spinningWheel release];
CGRect label = CGRectMake(142.0f, 255.0f, 71.0f, 20.0f);
lblLoading = [[UILabel alloc] initWithFrame:label];
lblLoading.textColor = [UIColor whiteColor];
lblLoading.font = [UIFont boldSystemFontOfSize:14];
// UILabel
lblLoading.backgroundColor =[UIColor clearColor];
[lblLoading setText:#"Loading..."];
//[lblLoading setTextAlignment:UITextAlignmentCenter];
[loadingView addSubview:lblLoading];
}
[window addSubview:loadingView];
}
- (void)hideLoadingView
{
[loadingView removeFromSuperview];
}
definitely if u apply this logic. u get succeed
I'd like to add a passcode lock in my app...
I created the view but I don't know how to get it working...
This is what I'd like it must do:
- If an user is setting his passcode, he must type it twice and the code must verify if the passcode typed the second time is the same of the first time.
- If the passcode controller is called by a setting view, for example, to set the passcode, it must have a cancel button on the navigation bar but if it is called at app launch, the cancel button mustn't be enabled.
summaryLabel is the label that show a message like "Passcode didn't match. Try again." when the passcode is not the same as the one written previously or saved.
EDIT1: How can I use textField:shouldChangeCharactersInRange:replacementString method to do this?
This is the code:#import "PasscodeController.h"
#implementation PasscodeController
#synthesize panelView;
#synthesize summaryLabel;
#synthesize titleLabel;
#synthesize textField1;
#synthesize textField2;
#synthesize textField3;
#synthesize textField4;
#synthesize hiddenTF;
-(void)viewDidLoad {
self.title = #"Passcode";
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 22, 270, 30)];
titleLabel.font = [UIFont boldSystemFontOfSize:15];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.textColor = [UIColor colorWithRed:66.0/255.0 green:85.0/255.0 blue:102.0/255.0 alpha:1.0];
titleLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:titleLabel];
[titleLabel release];
summaryLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 130, 270, 40)];
summaryLabel.font = [UIFont boldSystemFontOfSize:12];
summaryLabel.numberOfLines = 0;
summaryLabel.baselineAdjustment = UIBaselineAdjustmentNone;
summaryLabel.textAlignment = UITextAlignmentCenter;
summaryLabel.textColor = [UIColor colorWithRed:66.0/255.0 green:85.0/255.0 blue:102.0/255.0 alpha:1.0];
summaryLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:summaryLabel];
[summaryLabel release];
textField1 = [[UITextField alloc] initWithFrame:CGRectMake(25, 60, 60, 60)];
textField1.borderStyle = UITextBorderStyleBezel;
textField1.textColor = [UIColor blackColor];
textField1.textAlignment = UITextAlignmentCenter;
textField1.font = [UIFont systemFontOfSize:41];
textField1.secureTextEntry = YES;
textField1.backgroundColor = [UIColor whiteColor];
textField1.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField1];
[textField1 release];
textField2 = [[UITextField alloc] initWithFrame:CGRectMake(95, 60, 60, 60)];
textField2.borderStyle = UITextBorderStyleBezel;
textField2.textColor = [UIColor blackColor];
textField2.textAlignment = UITextAlignmentCenter;
textField2.font = [UIFont systemFontOfSize:41];
textField2.secureTextEntry = YES;
textField2.backgroundColor = [UIColor whiteColor];
textField2.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField2];
[textField2 release];
textField3 = [[UITextField alloc] initWithFrame:CGRectMake(165, 60, 60, 60)];
textField3.borderStyle = UITextBorderStyleBezel;
textField3.textColor = [UIColor blackColor];
textField3.textAlignment = UITextAlignmentCenter;
textField3.font = [UIFont systemFontOfSize:41];
textField3.secureTextEntry = YES;
textField3.backgroundColor = [UIColor whiteColor];
textField3.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField3];
[textField3 release];
textField4 = [[UITextField alloc] initWithFrame:CGRectMake(235, 60, 60, 60)];
textField4.borderStyle = UITextBorderStyleBezel;
textField4.textColor = [UIColor blackColor];
textField4.textAlignment = UITextAlignmentCenter;
textField4.font = [UIFont systemFontOfSize:41];
textField4.secureTextEntry = YES;
textField4.backgroundColor = [UIColor whiteColor];
textField4.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:textField4];
[textField4 release];
hiddenTF = [[UITextField alloc] initWithFrame:CGRectZero];
hiddenTF.hidden = YES;
hiddenTF.delegate = self;
hiddenTF.keyboardType = UIKeyboardTypeNumberPad;
[self.view addSubview:hiddenTF];
[hiddenTF release];
[hiddenTF becomeFirstResponder];
}
Thanks a lot!
Another solution, KVPasscodeViewController (mine), is available here: https://github.com/Koolistov/Passcode (BSD license).
If this can be helpful for other, I solved my problem with this source code on GitHub: PTPasscodeViewController.
I changed it a little bit to adapt it to my needs and now works greatly :)
If you want to use it, there are all the information about how to use it on the project page or in a file if you've downloaded it ;)
Hope this help!
P.S.: Thanks a lot to Lasha Dolidze to provide this code!
PINCode 1.0
there are 3 settings, in my app, that can be change the drawing of a cell.
By default, a cell of my table view show the name and the cost of an object... Changing these 3 setting, an user can choose to show a description or a link insted of cost.
I wrote a lot of code and now, my app can change cell's drawing without quit from it...
My problem is the drawing is changed only for new objects added but old objects don't change!
How can I do to change also the old cell's drawing without quit from app?
This is the code of my cell (i'm using setNeedsDisplay and drawRect methods):
#import "WishTableCell.h"
#implementation WishTableCell
#synthesize wish;
#synthesize imageView;
#synthesize nomeLabel;
#synthesize label;
#synthesize costoLabel;
#synthesize linkDescLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 11, 28, 28)];
imageView.contentMode = UIViewContentModeCenter;
[self.contentView addSubview:imageView];
nomeLabel = [[UILabel alloc] initWithFrame:CGRectMake(58, 8, 235, 22)];
[self.contentView addSubview:nomeLabel];
if ([NSLocalizedString(#"CostoCella", #"") isEqualToString:#"Costo:"]) {
label = [[UILabel alloc] initWithFrame:CGRectMake(58, 28, 40, 16)];
}
else {
label = [[UILabel alloc] initWithFrame:CGRectMake(58, 28, 35, 16)];
}
[self.contentView addSubview:label];
if ([NSLocalizedString(#"CostoCella", #"") isEqualToString:#"Costo:"]) {
costoLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 28, 185, 16)];
}
else {
costoLabel = [[UILabel alloc] initWithFrame:CGRectMake(93, 28, 195, 16)];
}
[self.contentView addSubview:costoLabel];
linkDescLabel = [[UILabel alloc] initWithFrame:CGRectMake(58, 28, 235, 16)];
[self.contentView addSubview:linkDescLabel];
self.backgroundView = [[UIImageView alloc] init];
UIImage *rowBackground = [UIImage imageNamed:#"cellBg.png"];
((UIImageView *)self.backgroundView).image = rowBackground;
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)setWish:(Wish *)newWish {
if (newWish != wish) {
[wish release];
wish = [newWish retain];
}
[self setNeedsDisplay];
}
-(void)drawRect:(CGRect)rect {
NSLog(#"DrawRect called!");
nomeLabel.text = wish.nome;
nomeLabel.font = [UIFont boldSystemFontOfSize:18.0];
nomeLabel.textColor = [UIColor colorWithRed:0.039 green:0.4 blue:0.737 alpha:1.0];
nomeLabel.textAlignment = UITextAlignmentLeft;
nomeLabel.shadowColor = [UIColor whiteColor];
nomeLabel.shadowOffset = CGSizeMake(0, 1);
nomeLabel.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:12.0];
label.text = NSLocalizedString(#"CostoCella", #"");
label.textColor = [UIColor colorWithRed:0.262 green:0.258 blue:0.258 alpha:1.0];
label.textAlignment = UITextAlignmentLeft;
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0, 1);
label.backgroundColor = [UIColor clearColor];
costoLabel.font = [UIFont boldSystemFontOfSize:12.0];
costoLabel.textColor = [UIColor colorWithRed:0.262 green:0.258 blue:0.258 alpha:1.0];
costoLabel.textAlignment = UITextAlignmentLeft;
costoLabel.shadowColor = [UIColor whiteColor];
costoLabel.shadowOffset = CGSizeMake(0, 1);
costoLabel.backgroundColor = [UIColor clearColor];
linkDescLabel.font = [UIFont boldSystemFontOfSize:12.0];
linkDescLabel.textColor = [UIColor colorWithRed:0.262 green:0.258 blue:0.258 alpha:1.0];
linkDescLabel.textAlignment = UITextAlignmentLeft;
linkDescLabel.shadowColor = [UIColor whiteColor];
linkDescLabel.shadowOffset = CGSizeMake(0, 1);
linkDescLabel.backgroundColor = [UIColor clearColor];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([[defaults objectForKey:#"dettagliView"] isEqualToString:#"costoView"]) {
linkDescLabel.hidden = YES;
label.hidden = NO;
costoLabel.hidden = NO;
if ([[defaults objectForKey:#"valutaCosto"] isEqualToString:#"Euro"]) {
NSString *costo = [[NSString alloc] initWithFormat:#"€ %#", wish.costo];
costoLabel.text = costo;
}
if ([[defaults objectForKey:#"valutaCosto"] isEqualToString:#"Dollaro"]) {
NSString *costo = [[NSString alloc] initWithFormat:#"$ %#", wish.costo];
costoLabel.text = costo;
}
if ([[defaults objectForKey:#"valutaCosto"] isEqualToString:#"Sterlina"]) {
NSString *costo = [[NSString alloc] initWithFormat:#"£ %#", wish.costo];
costoLabel.text = costo;
}
}
else if ([[defaults objectForKey:#"dettagliView"] isEqualToString:#"descrizioneView"]) {
label.hidden = YES;
costoLabel.hidden = YES;
linkDescLabel.hidden = NO;
linkDescLabel.text = wish.descrizione;
}
else if ([[defaults objectForKey:#"dettagliView"] isEqualToString:#"urlView"]) {
label.hidden = YES;
costoLabel.hidden = YES;
linkDescLabel.hidden = NO;
linkDescLabel.text = wish.link;
}
if (wish.categoria == nil)
imageView.image = [UIImage imageNamed:#"personale.png"];
if ([wish.categoria isEqualToString:#"Abbigliamento"])
imageView.image = [UIImage imageNamed:#"abbigliamento.png"];
else if ([wish.categoria isEqualToString:#"Casa"])
imageView.image = [UIImage imageNamed:#"casa.png"];
else if ([wish.categoria isEqualToString:#"Cibo"])
imageView.image = [UIImage imageNamed:#"cibo.png"];
else if ([wish.categoria isEqualToString:#"Divertimento"])
imageView.image = [UIImage imageNamed:#"divertimento.png"];
else if ([wish.categoria isEqualToString:#"Elettronica"])
imageView.image = [UIImage imageNamed:#"elettronica.png"];
else if ([wish.categoria isEqualToString:#"Hobby"])
imageView.image = [UIImage imageNamed:#"hobby.png"];
else if ([wish.categoria isEqualToString:#"Internet"])
imageView.image = [UIImage imageNamed:#"internet.png"];
else if ([wish.categoria isEqualToString:#"Regali"])
imageView.image = [UIImage imageNamed:#"regali.png"];
else if ([wish.categoria isEqualToString:#"Ufficio"])
imageView.image = [UIImage imageNamed:#"ufficio.png"];
else if ([wish.categoria isEqualToString:#"Viaggi"])
imageView.image = [UIImage imageNamed:#"viaggi.png"];
else if ([wish.categoria isEqualToString:#"Personale"])
imageView.image = [UIImage imageNamed:#"personale.png"];
}
- (void)dealloc {
[wish release];
[imageView release];
[nomeLabel release];
[costoLabel release];
[linkDescLabel release];
[label release];
[super dealloc];
}
#end
Thanks a lot for the attention!
Matthew
Try to call [NSTableView reloadData] function, and set the drawing properties in the delegate method (cellForRowAtIndexPath).
I think that you also can use interface to create the cell (.xib), then you do not need write so many assign property code....