[quote=bobby456;272311]Can you help me? I need to pass a Nsstring *urlString that is in viewController to an UIAlertView
[quote]
Since you're using a custom subview of UIAlertView, add a new NSString property to the alert view and set it when you create the alert. Like this:
viewController.m
Code:
sAlertView *alert1 = [[sAlertView alloc] initWithTitle:@"Options:" message:nil delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Test"];
alert1.tag = 10;
alert1.urlString = @"http://somedomain/somepath/somefile";
[alert1 show];
[alert1 release];
sAlert.h
Code:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <viewController.h>
@interface sAlertView : UIAlertView {
UIButton *controlButton;
MPMoviePlayerController *mMPPlayer;
}
@property (nonatomic, retain) UIImageView *controlButton;
@property (nonatomic, retain) NSString *urlString;
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle;
@end
sAlert.m
Code:
#import "sAlertView.h"
@implementation sAlertView
@synthesize urlString;
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString
*)cancelButtonTitle okButtonTitle:(NSString
*)okayButtonTitle{
if (self = [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil]) {
controlButton = [UIButton buttonWithType:UIButtonTypeCustom];
[controlButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
controlButton.frame = CGRectMake(125, 45, 35, 30);
[controlButton addTarget:self action:@selector(buttonPushed) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:controlButton];
} return self; }
- (void) buttonPushed{
mMPPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:urlString]];
[mMPPlayer play];
} ...
- (void) dealloc;
{
self.urlString = nil;
[super dealloc];
}