How/where in the code does the nib file get related to its *.m and *.h files?
Specifically I'm talking about when you create a new Objective-C class, not using the initWithNibName method.
I have a UITableViewController that contains a tableView. I want to set its scrollView delegate to self, but I am not sure how to do that? if i call
[self.tableView.delegate = self]
It will set the UITableViewDelegate to self, and not the UIScrollViewDelegate
Hi!
I'm generating an HTML file for an app, and in this HTML file there's a link to a stylesheet and one to an image.
Here's what I tried so far:
NSMutableString *toReturn = [NSMutableString stringWithCapacity:100];
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"etapes.css" ofType:nil];
[toReturn appendFormat:@"<html><head><title></title><link href=\"%@\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" /></head><body>", cssPath];
It generates the right full path to the right file, this is okay if I want to access it on my mac, but on the simulator or my iPhone it doesn't point to the right place at all...
Do you have any idea of how could I make this?
Thanks
I am trying to animate the color the the text on a UILabel to pulse from: [Black] to [White] to [Black] and repeat.
- (void)timerFlash:(NSTimer *)timer {
[[self navTitle] setTextColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]];
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{[[self navTitle] setTextColor:[[UIColor whiteColor] colorWithAlphaComponent:1.0]];}
completion:nil];
}
.
[self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFlash:) userInfo:nil repeats:YES]];
Firstly I am not sure of my method, my plan (as you can see above) was to set up a animation block and call it using a repeating NSTimer until canceled.
My second problem (as you can see above) is that I am animating from black (alpha 0) to white (alpha 1) but I don't know how to animate back to black again so the animation loops seamlessly
Essentially what I want is the text color to pulse on a UILabel until the user presses a button to continue.
EDIT_001:
I was getting into trouble because you can't animate [UILabel setColor:] you can however animated [UILabel setAlpha:] so I am going to give that a go.
EDIT_002:
- (void)timerFlash:(NSTimer *)timer {
[[self navTitle] setAlpha:0.5];
[UIView animateWithDuration:2
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{[[self navTitle] setAlpha:0.9];}
completion:nil];
}
This works (BTW: I do want it to stop which is why I hooked it up to a NSTimer so I can cancel that) the only thing is that this animates from midGray to nearWhite and then pops back. Does anyone know how I would animate back from nearWhite to midGray so I get a nice smooth cycle?
EDIT_003: (Solution)
The code suggested by dave DeLong (see below) does indeed work when modified to use the CALayer opacity style attribute:
UILabel *navTitle;
@property(nonatomic, retain) UILabel *navTitle;
.
// ADD ANIMATION
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
[anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[anim setFromValue:[NSNumber numberWithFloat:0.5]];
[anim setToValue:[NSNumber numberWithFloat:1.0]];
[anim setAutoreverses:YES];
[anim setDuration:0.5];
[[[self navTitle] layer] addAnimation:anim forKey:@"flash"];
.
// REMOVE ANIMATION
[[[self navTitle] layer] removeAnimationForKey:@"flash__"];
Seems like a simple thing but I can't seem to find a way to do it.
I saw this but it doesn't seem to work:
NSDate *date = [NSDate dateWithNaturalLanguageString:@"07/17/07"];
It would be great to see a couple different methods.
Thanks,
Nick
Title is quite self explanatory, but I have some animation being done in a loop triggered by UIDisplayLink. However, as soon as I scroll a UIScrollView I have added to my view hierarchy, the animation stops immediately, only to return again when scrolling has completely stopped and come to a standstill....
Anyway to cancel this behaviour?
I have a Paging UIScrollView with a contentSize large enough to hold a number of small UIScrollViews for zooming, The viewForZoomingInScrollView is a viewController that holds a CALayer for drawing a PDF page onto. This allows me to navigate through a PDF much like the ibooks PDF reader.
The code that draws the PDF (Tiled Layers) is located in:
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;
And simply adding a 'page' to the visible screen calls this method automatically. When I change page there is some delay before all the tiles are drawn, even though the object (page) has already been created.
What i want to be able to do is render the next page before the user scrolls to it, thus preventing the visible tiling effect. However, i have found that if the layer is located offscreen adding it to the scrollview doesn't call the drawLayer.
Any Ideas/common gotchas here?
I have tried:
[viewController.view.layer setNeedsLayout];
[viewController.view.layer setNeedsDisplay];
NB: The fact that this is replicating the ibooks functionally is irrelevant within the context of the full app.
I submitted my app a little over a week ago and got the dreaded rejection email today. It reads as follows:
Dear -----------,
Thank you for submitting --------- to the App Store. Unfortunately it cannot be added to the App Store because it is using a private API. Use of non-public APIs, which as outlined in the iPhone Developer Program License Agreement section 3.3.1 is prohibited:
"3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs."
The non-public API that is included in your application is firstResponder.
Regards,
iPhone Developer Program
Now, the offending API call is actually a solution I found here on SO:
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView *firstResponder = [keyWindow performSelector:@selector(firstResponder)];
So this is my question; How do I get the current first responder on the screen? I'm looking for a legal way that won't get my app rejected.
Thanks.
I figured this out based on the solution provided by Thomas below. Here is what the final code looks like:
@implementation UIView (FindFirstResponder)
- (UIView *)findFirstResonder
{
if (self.isFirstResponder) {
return self;
}
for (UIView *subView in self.subviews) {
UIView *firstResponder = [subView findFirstResonder];
if (firstResponder != nil) {
return firstResponder;
}
}
return nil;
}
@end
I have an app that has a username and password field. I want to validate the input before the the user is allowed to stop editing the field. To do that, I'm using the textFieldShouldEndEditing delegate method. If the input doesn't validate I display a UIAlertView.
This approach works as advertised - the user cannot leave the field if the input doesn't validate.
To have the done button on the keyboard dismiss the keyboard, I call resignFirstResponder on the textfield.
The issue I have is the alert is being called twice. How do I keep the alert from showing twice?
I have common functionality that I need to access from all screens of my app: a right bar button item and associated action.
So as not to repeat the code I would like to set this up in a custom UIViewController and have all my view controllers inherit from it.
- (void)viewDidLoad {
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(lightsCamera)];
self.navigationItem.rightBarButtonItem = rightBarButton;
}
- (void)lightsCamera {
…
}
However, I have a number of UITableViewControllers however and I would like to know if it is possible for them to inherit the functionality too?
Hi,
I checked out Apple's example on how to exchange detail views in the UISplitViewController (http://developer.apple.com/library/ios/#samplecode/MultipleDetailViews/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009775) and it seems that they put the UIToolbar in every detail controller. Then, if the device is rotated, they hide the toolbar or show it and add a popover button which will show the root controller.
I'd like to adopt this pattern to show my root controller in a popover using a button in the toolbar, but unfortunately, my detail controllers are all UITableViewControllers and they do not allow adding other UI elements than a table view. So how do I deal with that? Is there an example around?
René
Questions on calling web services from iPhone?
Anyone have any recommended tutorials on doing this?
Anyone have any best practices on implementing security with these calls?
Has anyone made or seen any shared libraries or wrappers for easy web service calls from the iPhone?
I have two 3rd party libraries that seem to use the same class. That should be fine but I'm getting this type of error when building:
ld: duplicate symbol .objc_class_name_CJSONScanner in /Users/myappOne/TapjoyConnect/Frameworks/libTapjoyConnectSimulatorRewardInstall_Ads_Pinch.a(CJSONScanner.o) and /Developer/Projects/BuildOutput/Debug-iphonesimulator/OtherLibrary_d.a(CJSONScanner.o)
How can I handle this issue?
Hi,
I have made a jokes application, where the user generates a joke and the joke will display in a UILabel. However I am trying to randomise the jokes show, but I do not want to show the same joke twice. Please could you tell me how I could do this. I am using the code below to try and do that, but it seems that it is not working.
- (IBAction)generateNewJoke {
if (i < [jokeArray count]) {
i++;
[userDefaults setInteger:[userDefaults integerForKey:kNewIndex] forKey:kOldIndex];
int oldnumber = [userDefaults integerForKey:kOldIndex];
int newnumber = [userDefaults integerForKey:kNewIndex];
[answerLabel setText:@""];
[userDefaults setInteger:i forKey:kNewIndex];
if (oldnumber == newnumber) {
NSLog(@"they are the same");
[userDefaults setInteger:arc4random()%[jokeArray count] forKey:kNewIndex];
}
[jokeLabel setText:[jokeArray objectAtIndex:[userDefaults integerForKey:kNewIndex]]];
}
}
Hi, I have a map image in a uiwebview. It default loads in the top left hand corner. I would like it to initialize in the center of the uiwebview.
Does anyone know how to do this?
Thanks!
Hi,
I am new in objective-c and I am trying to understand memory management to get it right.
After reading the excellent
Memory Management Programming Guide for Cocoa by apple my only concern is when
actually an autoreleased object is released in an iphone/ipod application. My understanding is at the end of a run loop. But what defines a run loop in the application?
So I was wondering whether the following piece of code is right. Assume an object
@implementation Test
- (NSString *) functionA {
NSString *stringA;
stringA = [[NSString alloc] initWithString:@"Hello" autorelease]
return stringA;
}
- (NSString *) functionB {
NSString *stringB;
stringB = [self functionA];
return stringB;
}
- (NSString *) functionC {
NSString *stringC;
stringC = [self functionB];
return stringC;
}
- (void)viewDidLoad {
[super viewDidLoad];
(NSString *) p = [self functionC];
NSLog(@"string is %@",p);
}
@end
Is this code valid?
From the apple text I understand that the NSString returned from functionA is valid in the scope of functionB. I am not sure whether it is valid in functionC and in viewDidLoad.
Thanks!
So, I thought consulting you guys about my design, cause I sense there might be a better way of doing it.
I need to implement game bonuses mechanism in my app.
Currently there are 9 bonuses available, each one is based of different param of the MainGame Object.
What I had in mind was at app startup to initialize 9 objects of GameBonus while each one will have different SEL (shouldBonus) which will be responsible for checking if the bonus is valid.
So, every end of game I will just run over the bonuses array and call the isBonusValid() function with the MainGame object(which is different after every game).
How's that sound ?
The only issue I have currently, is that I need to make sure that if some bonuses are accepted some other won't (inner stuff)... any advice how to do that and still maintain generic implementation ?
@interface GameBonus : NSObject {
int bonusId;
NSString* name;
NSString* description;
UIImage* img;
SEL shouldBonus;
}
@implementation GameBonus
-(BOOL) isBonusValid(MainGame*)mainGame
{
[self shouldBonus:mainGame];
}
@end
I have an iPhone project which references a framework as a subproject.
The framework has the following configurations:
Debug
Release
My app has the following configurations:
Debug
Release
Distribution-AdHoc
Distribution-AppStore
I would like the framework to be built with different configurations, depending on the app configuration:
Debug - Debug
Release - Release
Distribution-AdHoc - Release
Distribution-AppStore - Release
How can I achieve this?
I have several text fields in a custom uiviewcontroller subclass, which is displayed within a popover. The popover is displayed form a bar button. I want the keyboard to go down when the popover is dismissed (either by the user tapping the bar button again, or tapping outside the popover. From the view controller that displays the popover, when the popover is dismissed, in either of the 2 fashions, I call
[optionsController dismissFirstResponder];
Optionscontroller is the uiviewcontroller subclass in the popover. Dismissfirstresponder is a method I defined:
-(void)dsimissFirstResponder {
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];
}
Those are three IBoutlets which I connected in the xib to the text fields.
That doesn't work. Any help with this would be greatly appreciated.
Hi all, I have a table containing cells with phone numbers. How can I allow the user to dial these numbers by tapping the row? It's not working by default and there's no option in interface builder like there is for uiwebviews so I imagine I need to programmatically tell the app to dial the number when the cell is tapped.
Hello,
I'm trying to present some UIModalFormSheets in a my iPad application. It's working without any problems, except one thing:
When I have my iPad in landscape mode my modal form sheet is moving to the center of the screen and THEN rotates into the appropiate angle. All I want is to present the modal form sheet in the right angle according to the view mode (portrait or landscape), BEFORE it is displayed, so that the user doesn't see this rotation.
I have tried all the modes for modalTransitionStyle and modalPresentationStyle, but nothing seems to prevent the modal form sheet from rotating after it is displayed.
This is what I'm doing:
NewFavouriteSheet *newFavouriteSheet = [[NewFavouriteSheet alloc] initWithNibName:@"NewFavouriteSheet" bundle:nil];
newFavouriteSheet.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:newFavouriteSheet animated:NO];
Does anyone has a suggestion on how to show the modal view in a correct way?
Thanks for help.
Dominik
In my application one player and 10 targets are there. Each target appears one after the other (from target1 to target10). It's a shooting game. If we hit the first target then second target will come. The targets have properties like name, speedOfGunDraw, probability to hit the player, speedOfFire.
What should I do to make them appear one after the other with these properties. I am using CCMenuItem for the target. I am using a sprite for the player. Please give me idea to do this.
Thank You.
What are all the file formats supported by UIWebView?
In my testing, I found that it supports XLS, DOC, PPT, PDF but not XLSX, and DOCX, RTF.
It supports image files like, JPG, PNG, GIF, BMP, not sure about TIFF or
Exactly, what all types are supported is not clear...
The UIWebView documentation also doesn't state it clearly.
Could someone please help?