1) My annotation shows the title and subtitle of not.
I have already tried a lot, but I can not.
2) If an annotation has been selected, the annotation will be centered in the middle of the window. So the map is moved. Any idea?
3) My Callout button does not work anymore, I've got the # selector (openAnything) but I want to use this function is triggered - (void) mapView: (MKMapView *) mapView annotationView: (MKAnnotationView *) view calloutAccessoryControlTapped: (UIControl *) control {
Enough to ask, here's a video and some source code
http://www.youtube.com/watch?v=Ur1aqeYEFHw&feature=youtube_gdata_player
Thanks
TAPPMapViewControler.m
- (MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[TAPPMapAnnotation class]])
{
static NSString *shopAnnotationIdentifier = #"Filiale";
//pinView = (MKPinAnnotationView *)
TAPPMapAnnotationCustom* pinView = (TAPPMapAnnotationCustom*)[self.myMapView dequeueReusableAnnotationViewWithIdentifier:shopAnnotationIdentifier];
[self.myMapView dequeueReusableAnnotationViewWithIdentifier:shopAnnotationIdentifier];
if (pinView == nil)
{
// if an existing pin view was not available, create one
TAPPMapAnnotationCustom *customPinView = [[TAPPMapAnnotationCustom alloc] initWithAnnotation:annotation reuseIdentifier:shopAnnotationIdentifier];
customPinView.image = [UIImage imageNamed:#"map_pin.png"];
return customPinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
TAPPMapAnnotation *theAnnotation = view.annotation;
TAPPMapAnnotationDetail *theController = [self.storyboard instantiateViewControllerWithIdentifier:#"MapAnnotationDetail"];
theController.theAnnotationId = theAnnotation.objectId;
[self.navigationController pushViewController:theController animated:YES];
}
TAPPMapAnnotationCustom.h
#import <MapKit/MapKit.h>
#interface TAPPMapAnnotationCustom : MKAnnotationView
#property (strong, nonatomic) UIImageView *calloutView;
#property (strong, nonatomic) UILabel *title;
#property (strong, nonatomic) UILabel *subTitle;
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)animateCalloutAppearance:(BOOL)inAdd;
#end
TAPPMapAnnotationCustom.m
#import "TAPPMapAnnotationCustom.h"
#import "TAPPMapAnnotation.h"
#implementation TAPPMapAnnotationCustom
- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
[super setSelected:selected animated:animated];
if(selected)
{
// Remove Image, because we set a second large one.
self.image = Nil;
UIImage *imageBack = [[UIImage imageNamed:#"map_pin.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 35, 0, 6)];
self.calloutView = [[UIImageView alloc]initWithImage:imageBack];
[self.calloutView setFrame:CGRectMake(0,0,0,0)];
[self.calloutView sizeToFit];
[self addSubview:self.calloutView ];
// Callout Button
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:#selector(openAnything) forControlEvents:UIControlEventTouchUpInside];
rightButton.frame = CGRectMake(0
, ((self.calloutView.frame.size.height-6) / 2)-(rightButton.frame.size.height / 2)
, rightButton.frame.size.width
, rightButton.frame.size.height);
self.rightCalloutAccessoryView = rightButton;
self.rightCalloutAccessoryView.hidden = YES;
self.rightCalloutAccessoryView.alpha = 0;
[self addSubview:self.rightCalloutAccessoryView];
// Start Annimation
[self animateCalloutAppearance:YES];
} else {
//Start Annimation and Remove from view
[self animateCalloutAppearance:NO];
}
}
- (void)didAddSubview:(UIView *)subview{
if ([[[subview class] description] isEqualToString:#"UICalloutView"]) {
for (UIView *subsubView in subview.subviews) {
if ([subsubView class] == [UIImageView class]) {
UIImageView *imageView = ((UIImageView *)subsubView);
[imageView removeFromSuperview];
}else if ([subsubView class] == [UILabel class]) {
UILabel *labelView = ((UILabel *)subsubView);
[labelView removeFromSuperview];
}
}
}
}
- (void)animateCalloutAppearance:(BOOL)inAdd {
if (inAdd == YES) {
self.rightCalloutAccessoryView.hidden = NO;
[UIView animateWithDuration:0.4 delay:0 options: UIViewAnimationOptionTransitionNone
animations:^{
self.calloutView.frame = CGRectMake(self.calloutView.frame.origin.x
, self.calloutView.frame.origin.y
, self.calloutView.frame.size.width+150
, self.calloutView.frame.size.height);
self.rightCalloutAccessoryView.alpha = 1;
self.rightCalloutAccessoryView.frame = CGRectMake(self.calloutView.frame.size.width - (self.rightCalloutAccessoryView.frame.size.width)
, self.rightCalloutAccessoryView.frame.origin.y
, self.rightCalloutAccessoryView.frame.size.width
, self.rightCalloutAccessoryView.frame.size.height);
} completion:^(BOOL finished){ }];
} else {
[UIView animateWithDuration:0.4 delay:0 options: UIViewAnimationOptionTransitionNone
animations:^{
self.rightCalloutAccessoryView.alpha = 0;
self.rightCalloutAccessoryView.frame = CGRectMake(0
, self.rightCalloutAccessoryView.frame.origin.y
, self.rightCalloutAccessoryView.frame.size.width
, self.rightCalloutAccessoryView.frame.size.height);
self.calloutView.frame = CGRectMake(self.calloutView.frame.origin.x
, self.calloutView.frame.origin.y
, self.calloutView.frame.size.width-150
, self.calloutView.frame.size.height);
} completion:^(BOOL finished){
self.image = [UIImage imageNamed:#"map_pin.png"];
[self.calloutView removeFromSuperview];
[self.rightCalloutAccessoryView removeFromSuperview];
}];
}
}
#end
Your annotation class needs to have a subtitle attribute, yours has subTitle.
If calloutAccessoryControlTapped is not being called it is usually a sign your MKMapview's delegate has not been set. However you're only setting the accessory button when it gets selected. Do you have a good reason for that? Since the callout window won't be visible until it is selected, I would advise you to set the accessory button in viewForAnnotation and let it appear when the callout window does.
I fix the first one:
TAPPMapAnnotation *theAnnotation = (TAPPMapAnnotation *)self.annotation;
self.title = [[UILabel alloc]init];
self.title.font = [UIFont systemFontOfSize:12.0];
self.title.textColor = [UIColor whiteColor];
self.title.backgroundColor = [UIColor clearColor];
self.title.text = theAnnotation.title;
[...]
[self.theView addSubview:self.title];
Related
I'm trying to display a list of web pages the user can switch between in my app. I've done this successfully with documents. however, I don't want the user to be able to navigate from these pages. I found out how to do this by looking it up. The problem is that it only executes on the first page. When I switch to another page shouldStartLoadWithRequest stops working even when I go back to the first page. (This is all done with my specially designed back and forward buttons.) How can I fix this so that it will be invoked every single time and prevent the user from clicking links and navigating away from my set pages? I'm new to objective-c. All the relevant code is below. Some things were declared globally in the .h. Sorry it's kind of rough. I tabbed over only what was needed to make it into code formatting. Thanks!
My .h file:
#import <UIKit/UIKit.h>
#interface learnViewController : UIViewController <UINavigationControllerDelegate>
{
IBOutlet UIWebView *web;
UIButton *backButton;
UIButton *forButton;
}
#end
My .m file
#import "learnViewController.h"
#import "ViewController.h"
static NSString* links[] =
{
#"http://www.nlm.nih.gov/medlineplus/ency/article/000141.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/000065.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/001087.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/000091.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/007270.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/000145.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/000093.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/000087.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/000140.htm",
#"http://www.nlm.nih.gov/medlineplus/ency/article/000132.htm"
};
int numlinks = 10;
int i = 0;
#interface learnViewController ()
#end
#implementation learnViewController
- (void)viewDidLoad
{
[super viewDidLoad];
float viewWidth = self.view.frame.size.width;
float viewHeight = self.view.frame.size.height;
self.view.multipleTouchEnabled = true;
//Background
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, viewWidth, viewHeight)];
backgroundView.image = [UIImage imageNamed:#"Background.png"];
[self.view addSubview:backgroundView];
//Show Portal
web = [[UIWebView alloc]initWithFrame:CGRectMake(0.0, viewHeight/34.0, viewWidth, (viewHeight - viewHeight/6.4))];
self->web.delegate = self;
web.scrollView.scrollEnabled = TRUE;
web.scalesPageToFit = TRUE;
[self loadDocument:links[i] inView:web];
[self.view addSubview:web];
//Buttons
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake((viewWidth/2.0 - viewWidth/6.0/2.0), (viewHeight - viewHeight*280.0/2208.0/2.0 - viewWidth/6.0/2.0), (viewWidth/6.0), (viewWidth/6.0))];
[homeButton
setBackgroundImage:[UIImage imageNamed:#"Home.png"]
forState:UIControlStateNormal];
[homeButton addTarget:self action:#selector(homePressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:homeButton];
backButton = [[UIButton alloc] initWithFrame:CGRectMake((viewWidth/2.0/3.5 - viewWidth/9.0/2.0), (viewHeight - viewHeight*280.0/2208.0/2.0 - viewWidth/9.0/2.0), (viewWidth/9.0), (viewWidth/9.0))];
[backButton
setBackgroundImage:[UIImage imageNamed:#"Back.png"]
forState:UIControlStateNormal];
backButton.enabled = FALSE;
[backButton addTarget:self
action:#selector(backPressed:)
forControlEvents:UIControlEventTouchDown];
[self.view addSubview:backButton];
forButton = [[UIButton alloc] initWithFrame:CGRectMake((viewWidth/2.0/3.5*2.0 - viewWidth/9.0/2.0), (viewHeight - viewHeight*280.0/2208.0/2.0 - viewWidth/9.0/2.0), (viewWidth/9.0), (viewWidth/9.0))];
[forButton
setBackgroundImage:[UIImage imageNamed:#"Forward.png"]
forState:UIControlStateNormal];
[forButton addTarget:self
action:#selector(forPressed:)
forControlEvents:UIControlEventTouchDown];
[self.view addSubview:forButton];
UIButton *refButton = [[UIButton alloc] initWithFrame:CGRectMake((viewWidth - viewWidth/2.0/3.5*2.0 - viewWidth/9.0/2.0), (viewHeight - viewHeight*280.0/2208.0/2.0 - viewWidth/9.0/2.0), (viewWidth/9.0), (viewWidth/9.0))];
[refButton
setBackgroundImage:[UIImage imageNamed:#"Scale.png"]
forState:UIControlStateNormal];
[refButton addTarget:self
action:#selector(refPressed:)
forControlEvents:UIControlEventTouchDown];
[self.view addSubview:refButton];
UIButton *webButton = [[UIButton alloc] initWithFrame:CGRectMake((viewWidth - viewWidth/2.0/3.5 - viewWidth/9.0/2.0), (viewHeight - viewHeight*280.0/2208.0/2.0 - viewWidth/9.0/2.0), (viewWidth/9.0), (viewWidth/9.0))];
[webButton
setBackgroundImage:[UIImage imageNamed:#"Web.png"]
forState:UIControlStateNormal];
[webButton addTarget:self
action:#selector(webPressed:)
forControlEvents:UIControlEventTouchDown];
[self.view addSubview:webButton];
}
//Button presses
-(void)homePressed:(id)sender
{
ViewController *home = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:home animated:YES completion:NULL];
}
- (void) refPressed:(id)sender
{
[self loadDocument:links[i] inView:web];
}
-(void)backPressed:(id)sender
{
float viewWidth = self.view.frame.size.width;
float viewHeight = self.view.frame.size.height;
if (i > 0)
{
[web removeFromSuperview];
i--;
web = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, viewHeight/34.0, viewWidth, (viewHeight - viewHeight/6.4))];
[self loadDocument:links[i] inView:web];
web.scrollView.scrollEnabled = TRUE;
web.scalesPageToFit = TRUE;
[self.view addSubview:web];
forButton.enabled = TRUE;
}
if (i == 0)
{
backButton.enabled = FALSE;
}
}
-(void)forPressed:(id)sender
{
float viewWidth = self.view.frame.size.width;
float viewHeight = self.view.frame.size.height;
if (i < numlinks - 1)
{
[web removeFromSuperview];
i++;
web = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, viewHeight/34.0, viewWidth, (viewHeight - viewHeight/6.4))];
[self loadDocument:links[i] inView:web];
web.scrollView.scrollEnabled = TRUE;
web.scalesPageToFit = TRUE;
[self.view addSubview:web];
backButton.enabled = TRUE;
}
if (i == numlinks - 1)
{
forButton.enabled = FALSE;
}
}
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *url = links[i];
NSURL *nsurl = [NSURL URLWithString:url];
NSURLRequest *nsrequest = [NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
}
-(void)webPressed:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:links[i]]];
}
-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSRange range = [urlString rangeOfString:links[i]];
if (range.location != NSNotFound)
{
return YES;
}
else
{
return NO;
}
}
- (void)viewDidUnload
{
[self->web stopLoading];
self->web.delegate = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Okay, I figured it out through trial and error since no one wanted to help me. I tried looking for answers to similar questions, but nothing actually worked for me. If you're reading this and having the same problem, this is how you fix it. All you have to do is reset the web delegate to nil then back to self as so:
self.webView.delegate = nil;
self.webView.delegate = self;
I don't know why everyone else's code was so complex, and I can only speculate as to why this works. I just got lucky honestly, but I think it maybe clears the cache when you do this, thus making each page fresh to the program. That's what other people were talking about. However, their methods did not work for me either because of my lack of experience or because they do not fit my particular case. This is much simpler and is guaranteed to work as long as you make sure it does this each time you load one of your designated web pages. You're welcome if you're reading this. If anyone would so kindly as to look at my post and explain why this works in better detail, please feel free to do so!
I have given a webview in Sectioned UiTableViewCell like this
if(section==0)
{
static NSString *CellIdentifier=#"Cell";
UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
webView = [[UIWebView alloc] initWithFrame:CGRectZero];
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
webView.tag = 1001;
webView.userInteractionEnabled = NO;
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[cell addSubview:webView];
}
webView = (UIWebView*)[cell viewWithTag:1001];
webView.delegate=self;
webView.frame=CGRectMake(0, 0, 300, 1000);
NSLog(#"current mode: %#", [[NSRunLoop currentRunLoop] currentMode]);
[webView loadHTMLString: [NSString stringWithFormat:[arrSecCount objectAtIndex:0], indexPath.section]baseURL:nil];
return cell;
}
where as the content in webview is dynamic.in
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section==0)
{
NSString *output = [webView stringByEvaluatingJavaScriptFromString:#"document.body.scrollHeight;"];
return [output floatValue]+300;
}
}
but when content in webview increases it is overiding on other section not fitting height.i have been tried many methodson search but of no use.
Help me with your suggestions
I think the UITableViewCell will get its height before the content of the WebView is even loaded...
What is suggest is that in the delegate method of the webview :
- (void)webViewDidFinishLoad:(UIWebView *)webView
you do a
[tableView reloadData];
That means you have to keep a reference to the webview and not reloading the HTMLString everytime the cell content is updated...
I have written a Singleton Class for managing iAds.The iAds pop up after 5 seconds of the user inactivity. The idleTimerExceeded call generate a notification to show the iAd. This code works fine for my requirements but since I am new to iOS development, my application sometimes hangs unexpectedly after integrating this code. This code results in lots of warnings etc. I would like to optimize my code in terms of memory and performance.
I would be very thankful for your kind suggestions and reviews.
Below is my code:
iAdSingleton.h
#import <Foundation/Foundation.h>
#import "AppDelegate.h"
#import "iAd/iAd.h"
#interface iAdSingleton : UIViewController<ADBannerViewDelegate> {
ADBannerView *adView;
UIViewController *displayVC;
NSTimer *idleTimer;
BOOL isItFirstTime;
}
#property (nonatomic, retain) ADBannerView *adView;
#property (nonatomic, retain) UIViewController *displayVC;
#property (nonatomic) BOOL isItFirstTime;
+ (id) shareAdSingleton;
- (void) resetIdleTimer;
- (void) idleTimerExceeded;
#end
iAdSingleton.m
#import "iAdSingleton.h"
#implementation iAdSingleton
static iAdSingleton* _sharedAdSingleton = nil;
BOOL bannerVisible = NO;
BOOL controlAccessBannerVisibility = NO;
#synthesize adView, displayVC;
#synthesize isItFirstTime;
#define kMaxIdleTimeSeconds 5.0
+(id)sharedAdSingleton
{
#synchronized(self)
{
if(!_sharedAdSingleton)
_sharedAdSingleton = [[self alloc] init];
return _sharedAdSingleton;
}
return nil;
}
+(id)alloc
{
#synchronized([iAdSingleton class])
{
NSAssert(_sharedAdSingleton == nil, #"Attempted to allocate a second instance of a singleton.");
_sharedAdSingleton = [super alloc];
return _sharedAdSingleton;
}
return nil;
}
-(id)init
{
self = [super init];
if (self != nil) {
/* Initialize The Parameters Over Here */
//adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 480, 0, 0)];
adView = [[ADBannerView alloc] init];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
self.adView.delegate=self;
[self resetIdleTimer];
}
return self;
}
-(void)dealloc
{
displayVC = nil;
if (adView) {
[adView removeFromSuperview]; //Remove ad view from superview
[adView setDelegate:nil];
adView = nil;
}
[super dealloc];
}
-(UIViewController *)viewControllerForPresentingModalView
{
return displayVC;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
banner.hidden = NO;
if(!bannerVisible){
NSLog(#"Banner Changes 1 - Purpose: Visibility");
// [UIView beginAnimations:#"bannerAppear" context:NULL];
// banner.frame = CGRectOffset(banner.frame, 0, -100);
// [UIView commitAnimations];
bannerVisible = YES;
controlAccessBannerVisibility = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
//NSLog(#"Unable to receive Ad.");
NSLog(#"Banner Changes 2 - Purpose: Unable to Receive Ad.");
banner.hidden = YES;
if(bannerVisible){
[UIView beginAnimations:#"bannerDisappear" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0, 100);
[UIView commitAnimations];
bannerVisible = NO;
}
}
- (BOOL) bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(#"Pause anything necessary");
return YES;
}
- (void) bannerViewActionDidFinish:(ADBannerView *)banner
{
NSLog(#"We now resume to normal operations");
}
- (void)resetIdleTimer {
if (!idleTimer) {
idleTimer = [[NSTimer scheduledTimerWithTimeInterval:kMaxIdleTimeSeconds
target:self
selector:#selector(idleTimerExceeded)
userInfo:nil
repeats:NO] retain];
}
else {
if (fabs([idleTimer.fireDate timeIntervalSinceNow]) < kMaxIdleTimeSeconds-1.0) {
[idleTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:kMaxIdleTimeSeconds]];
/*
Notification: HideAd
*/
NSLog(#"Notification Generated For HideAd");
[[NSNotificationCenter defaultCenter] postNotificationName:#"HideAdBanner" object:nil userInfo:nil];
}
}
}
- (void)idleTimerExceeded {
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (appDel.adVisible == NO) {
NSLog(#"Notification Generated For ShowAd");
/*
Notification: ShowAd
*/
if (controlAccessBannerVisibility == YES) {
[[NSNotificationCenter defaultCenter] postNotificationName:#"ShowAdBanner" object:nil userInfo:nil];
}
}
}
#end
This is what you need. This code is thread safe as well as will not have any memory issue and warnings.
+ (iAdSingleton *) sharedInstance
{
static dispatch_once_t onceToken;
static iAdSingleton * __sharedInstance = nil;
dispatch_once(&onceToken, ^{
__sharedInstance = [[self alloc] init];
});
return __sharedInstance;
}
I need to display a detailed view controller with multiple labels when a row in a table view is clicked. The labels I am displaying are of dynamic height based on the content, which is being read from the iPhone's internal calendar. I have been able to implement the loading of detail views based on which row in the table view has been selected. My issue is that the previous detail view does not get cleared up when a new row is clicked. Especially in the case when my previous detail view had longer labels and the new detail view has shorter labels, I can see the content of the previous labels below the new one. How can I clear up the entire Detail View controller before reloading it with the new row's data. Following is the code I am using:
RootViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (mdController == nil) {
MtgDetailController *aController = [[MtgDetailController alloc] initWithNibName:#"MtgDetailController" bundle:nil];
self.mdController = aController;
[aController release];
}
self.mdController.mtgIndex = indexPath.row;
// mdController.mtgIndex = indexPath.row;
// [mdController setMtgIndex:indexPath.row];
// NSInteger temp = indexPath.row;
UIActionSheet *action = [[UIActionSheet alloc]
initWithTitle:#"Select an Option"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Open Meeting", #"Dial into meeting", nil];
[action showInView:self.parentViewController.view];
[action release];
}
MtgDetailController.m (This is the Detail View Controller)
-(void) viewDidAppear:(BOOL)animated {
// [self reloadInputViews];
Smart_MeetingAppDelegate *myDelegate = (Smart_MeetingAppDelegate *)[[UIApplication sharedApplication]delegate];
CGRect scrollViewFrame = CGRectMake(0, 0, 320, 460);
NSString *title = [myDelegate.titles objectAtIndex:self.mtgIndex];
NSString *mtg_time = [myDelegate.mtg_times objectAtIndex:self.mtgIndex];
NSString *loc = #"Conf Room 123";
// detail = #"test mtg test mtg. Dial number: 3334445555, (333)444-5555, 333-333-5555. ID: 4455333344, Password: 6576567";
detail = [myDelegate.detail_array objectAtIndex:self.mtgIndex];
NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:#"\\b[0-9]+(\\-)?(\\))?(\\.)?(\\s)?([0-9]+)?(\\-)?(\\.)?(\\s)?([0-9]+)?(\\-)?(\\.)?(\\s)?([0-9]+)?\\b" options:NSRegularExpressionCaseInsensitive error:nil];
NSArray* matches = [regex matchesInString:detail options:0 range:NSMakeRange(0, [detail length])];
[regex release];
unichar chr[1] = {'\n'};
NSString *singleCR = [NSString stringWithCharacters:(const unichar *)chr length:1];
NSString *titleRow = [NSString stringWithFormat:#"%# %# %#", title, singleCR, mtg_time];
NSMutableAttributedString *attrTitle = [NSMutableAttributedString attributedStringWithString:titleRow];
[attrTitle setFont:[UIFont systemFontOfSize:18] range:[titleRow rangeOfString:title]];
[attrTitle setFont:[UIFont systemFontOfSize:16] range:[titleRow rangeOfString:mtg_time]];
NSMutableAttributedString *attrLoc = [NSMutableAttributedString attributedStringWithString:loc];
NSMutableAttributedString *attrDetail = [NSMutableAttributedString attributedStringWithString:detail];
[attrDetail setFont:[UIFont systemFontOfSize:16]];
CGSize suggestedSize = [attrTitle sizeConstrainedToSize:CGSizeMake(300, FLT_MAX)];
CGRect frame1 = CGRectMake(10, 15, 300, suggestedSize.height);
OHAttributedLabel *lblTitle = [[OHAttributedLabel alloc] initWithFrame:frame1];
lblTitle.numberOfLines = 0;
CGSize size2 = [attrLoc sizeConstrainedToSize:CGSizeMake(300, FLT_MAX)];
CGRect frame2 = CGRectMake(10, suggestedSize.height+15+5, 300, size2.height);
OHAttributedLabel *lblLocation = [[OHAttributedLabel alloc] initWithFrame:frame2];
CGFloat temp = size2.height+suggestedSize.height;
CGSize size3 = [attrDetail sizeConstrainedToSize:CGSizeMake(300, FLT_MAX)];
CGRect frame3 = CGRectMake(10, temp+15+5, 300, size3.height);
OHAttributedLabel *lblDescription = [[OHAttributedLabel alloc] initWithFrame:frame3];
lblDescription.numberOfLines = 0;
lblTitle.attributedText = attrTitle;
lblLocation.attributedText = attrLoc;
lblDescription.attributedText = attrDetail;
for (NSTextCheckingResult *m in matches) {
NSString *num = [detail substringWithRange:m.range];
NSRange linkRange = [detail rangeOfString:num];
[lblDescription addCustomLink:[NSURL URLWithString:#"user://certa"] inRange:linkRange];
}
lblDescription.delegate = self;
[self.view addSubview:lblTitle];
[self.view addSubview:lblDescription];
[self.view addSubview:lblLocation];
[lblTitle release];
[lblLocation release];
[lblDescription release];
}
You add three new instances of OHAttributedLabel to your detail view every time viewDidAppear: executes. You never remove these views. You need to save references to them (lblTitle, lblDescription, and lblLocation) in your MtgDetailController, and either remove them or reuse them the next time viewDidAppear: executes.
Add three properties to your MtgDetailController:
#property (retain) UILabel *lblTitle;
#property (retain) UILabel *lblDescription;
#property (retain) UILabel *lblLocation;
(Don't forget to #synthesize them too.)
At the top of viewDidAppear:, remove the labels from their superviews:
- (void)viewDidAppear:(BOOL)animated {
[self.lblTitle removeFromSuperview];
[self.lblDescription removeFromSuperview];
[self.lblLocation removeFromSuperview];
...
At the bottom of viewDidAppear:, save your newly-created labels in the properties:
self.lblTitle = lblTitle;
self.lblLocation = lblLocation;
self.lblDescription = lblDescription;
Hi when I am compiling my code i am getting this error-"accessing unknown 'flipDelegate' component of a property"
this is the code from where i am getting error-
//
// RootViewController.m
// Dolphia
//
// Created by Dolphia Nandi on 4/3/11.
// Copyright 2011 State University of New York at Buffalo. All rights reserved.
//
#import "RootViewController.h"
#import "MainViewController.h"
#import "FlipSideViewController.h"
#implementation RootViewController
#synthesize mainViewController;
#synthesize flipSideViewController;
- (void)loadMainViewController {
MainViewController *viewController = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
self.mainViewController = viewController;
self.mainViewController.flipDelegate = self;
[viewController release];
}
- (void)loadFlipSideViewController {
FlipSideViewController *viewController = [[FlipSideViewController alloc] initWithNibName:#"FlipSideViewController" bundle:nil];
self.flipSideViewController = viewController;
self.flipSideViewController.flipDelegate = self;
[viewController release];
}
- (void)viewDidLoad {
[self loadMainViewController]; // Don't load the flipside view unless / until necessary
[self.view addSubview:mainViewController.view];
}
// This method is called when either of the subviews send a delegate message to us.
// It flips the displayed view from the whoever sent the message to the other.
- (void)toggleView:(id)sender {
if (flipSideViewController == nil) {
[self loadFlipSideViewController];
}
UIView *mainWindow = mainViewController.view;
UIView *flipSideView = flipSideViewController.view;
/*[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
if(flipeffect >= 0 && flipeffect < 2) {
flipeffect++;
[UIView setAnimationTransition:((voiceViewController == sender) ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
} else if (flipeffect >= 2 && flipeffect < 4) {
flipeffect++;
[UIView setAnimationTransition:((voiceViewController == sender) ? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown) forView:self.view cache:YES];
} else if (flipeffect >= 4 && flipeffect < 6) {
flipeffect++;
[UIView setAnimationTransition:((voiceViewController == sender) ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:self.view cache:YES];
} else {
flipeffect++;
if(flipeffect > 7)
flipeffect = 0;
[UIView setAnimationTransition:((voiceViewController == sender) ? UIViewAnimationTransitionCurlDown : UIViewAnimationTransitionCurlUp) forView:self.view cache:YES];
}*/
if (mainViewController == sender) {
[flipSideViewController viewWillAppear:YES];
[mainViewController viewWillDisappear:YES];
[mainWindow removeFromSuperview];
[self.view addSubview:flipSideView];
[mainViewController viewDidDisappear:YES];
[flipSideViewController viewDidAppear:YES];
} else {
[mainViewController viewWillAppear:YES];
[flipSideViewController viewWillDisappear:YES];
[flipSideView removeFromSuperview];
[self.view addSubview:mainWindow];
[flipSideViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
}
//[UIView commitAnimations];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[mainViewController release];
[flipSideViewController release];
[super dealloc];
}
#end
Both mainViewController and flipSideViewController should have flipDelegate as instance variable and make sure you add #synthesize and #property