my project won't show the web view no matter what code i try use. I even tried a youtube tutorial. I know this question has been asked many times but it doesn't make sense to me. I used this tutorial https://www.youtube.com/watch?v=AmMF7hWrYZk
Heres my code
If you need more detail please ask me. I'm knew to objective c
ViewController.m
// FirstViewController.m
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
ViewController.h
//
// FirstViewController.h
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIWebView *webView;
#end
Related
Does anyone know how to leave pdf with webview
this app is done with xcode,i learn it from internet
but I got a issue, when I click a download link
it would open the file in app , but I can't go back to
previous page , I can't do anything but close app & restart
So what should I add to make app go back to previous page
here is my app ,
viewcontroller.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIWebView *webview;
#end
viewcontroller.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *url = [NSURL URLWithString:#"http://mywebsite/index.php"];
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I have a method which need receive a Byte[] :
In the .h file:
- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;
In the .m file:
I want to own a Byte[] property to save it.
But when I declare the property like this:
#property (nonatomic, assign) Byte PC1_APPKEY[];
It shows error:property cannot have array or function type'Byte[]'
And so I set it to attribute like this:
{
Byte PC1_APPKEY[];
}
It shows error:Field has Incomplete type ‘Byte[]’
How can I get the Byte[] ? thanks.
you can use Pointer like this
#property (nonatomic, assign) Byte *PC1_APPKEY;
all files
.h
//
// ocViewController.h
// testTableViewHeader
//
// Created by 刷脸卡 on 10/11/16.
// Copyright © 2016 曾祥林. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface TestViewController : UIViewController
- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;
#end
.m
//
// ocViewController.m
// testTableViewHeader
//
// Created by 刷脸卡 on 10/11/16.
// Copyright © 2016 曾祥林. All rights reserved.
//
#import "TestViewController.h"
#interface TestViewController ()
#property (nonatomic, assign) Byte *PC1_APPKEY;
#end
#implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *testString = #"1234567890";
NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
self.PC1_APPKEY = (Byte *)[testData bytes];
for(int i=0;i<[testData length];i++){
printf("testByte = %d\n",self.PC1_APPKEY[i]);
}
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setPC1_APPKEY:(Byte [])pC1_APPKEY{
self.PC1_APPKEY = pC1_APPKEY;
}
#end
I am building an iPhone 6 app for a friend's store. I wanted to have a video intro automatically playing when the initial view controller starts. I get no sound or audio.
I have on my storyboard a UIViewController, and in it a view that I re-classified as AVPlayerClass
I have also added added cupcake1.mov (QuickTime format) under "Supporting Files".
// AppDelegate.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
//
// AppDelegate.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
//
// ViewController.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import "AVPlayerClass.h"
#class AVPlayer;
#class AVPlayerClass;
#interface ViewController : UIViewController
#property (nonatomic, strong) AVPlayer *player;
#property (nonatomic, strong) AVPlayerClass *playerView;
#end
//
// ViewController.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize player;
#synthesize playerView;
- (void)viewDidLoad {
[super viewDidLoad];
[self setupMovie];
}
- (void)setupMovie
{
NSURL *url = [[NSBundle mainBundle]URLForResource:#"cupcake1" withExtension:#"mov"];
self.player = [AVPlayer playerWithURL: url];
[self.playerView setMovieToPlayer:player];
[self.player play];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
//
// AVPlayerClass+.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#class AVPlayer;
#interface AVPlayerClass : UIView
#property (nonatomic, retain) AVPlayer* player;
- (void)setMovieToPlayer:(AVPlayer*)player;
#end
//
// AVPalyerClass.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "AVPlayerClass.h"
#implementation AVPlayerClass
+ (Class)layerClass
{
return [AVPlayerLayer class];
}
-(AVPlayer*)player
{
return [(AVPlayerLayer*) [self layer] player];
}
- (void)setMovieToPlayer:(AVPlayer *)player
{
[(AVPlayerLayer*)[self layer] setPlayer: player];
}
#end
//
// main.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I just created a sample project just like yours and have my movie playing and used the MPMoviePlayerController class.
I launched Xcode and created a new iOS application project based on the Single View Application template.
I took a random sample movie file from vimeo, downloaded it, and copied it to my project calling it "movie.mp4".
In the ViewController.m I followed the following three steps:
#import <MediaPlayer/MediaPlayer.h>>
added a movieplayer property:
#property (nonatomic) MPMoviePlayerController *moviePlayer;
in viewDidLoad I added the following code:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"movie" ofType:#"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
self.moviePlayer.shouldAutoplay = YES;
[self.moviePlayer setFullscreen:YES animated:YES];
UIView *videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[self.moviePlayer.view setFrame:videoView.bounds];
[videoView addSubview:self.moviePlayer.view];
[self.view addSubview:videoView];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
}
I built and run and I am able to watch the movie and go fullscreen.
I tested on device and the movie plays.
If you get this far then you can adjust to your specific UI.
Hope this helps.
I'm working on my first ground-up iOS app. I'm sure I'm doing something wrong here, but I can't seem to ferret out the problem.
I have an app with some IBActions in it, which do two things:
1) Outputs some simple text via NSLog (to let me know the action worked) - this works okay (it outputs my text via NSLog)
2) Makes a call to a method in a custom class which should also output an NSLog statement. - this doesn't work (no text output via NSLog)
I'm also struggling a bit with where to create the instances of my classes so that they are accessible elsewhere in my code.
Here's the code:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController {
// Variables that you want to access globally go here?
Player *wizard;
Orc *grunty;
}
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
and
//
// ViewController.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "ViewController.h"
#import "Player.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)takePie:(id)sender{
// Player attempts to take the pie
// If Orc's health is > 0, don't let the player take the pie
// If the Orc's health is <= zero, let the player take the pie
NSLog(#"IBAction - player attempted to take the pie.");
[wizard takePie];
}
-(IBAction)castFireball:(id)sender{
NSLog(#"IBAction - player cast fireball.");
[wizard castFireball];
}
-(IBAction)attack:(id)sender{
NSLog(#"IBAction - player attacked.");
[wizard attackOrc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Player *wizard = [[Player alloc]init];
Orc *grunty = [[Orc alloc]init];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and
//
// Player.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <Foundation/Foundation.h>
#interface Player : NSObject
#property int maxHealth;
#property int currentHealth;
#property int armorClass;
#property int meleeToHitModifier;
-(void)setHeathBar;
-(void)attackOrc;
-(void)castFireball;
-(void)takePie;
#end
and
//
// Player.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "Player.h"
#implementation Player
#synthesize maxHealth;
#synthesize currentHealth;
#synthesize armorClass;
#synthesize meleeToHitModifier;
-(void)setHealthBar {
NSLog(#"Player health is 15");
return;
}
-(void)attackOrc {
// roll a d20
// add the "to hit" modifier
// compare the result to the orc's armor class
NSLog(#"Player - Player attached the Orc");
return;
}
-(void)castFireball{
NSLog(#"Player - Player casts Fireball");
return;
}
-(void)takePie{
NSLog(#"Player - Player attempts to take pie");
return;
}
#end
Note: I also have an Orc class defined, but it looks fairly identical to the player class shown.
Thanks in advance for the help!
-- Eddie
Your ViewController.h (which you should call by some more distinctive name, FYI) should look like this:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController
#property Player *wizard;
#property Orc *grunty;
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
Then in your ViewController.m, your viewDidLoadMethod should look like:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.wizard = [[Player alloc]init];
self.grunty = [[Orc alloc]init];
}
This should at least ensure you have an instantiated instance of Player that you can call methods on, so your NSLog should be reached.
I'm just starting to learn Xcode, and have run in to some problems...
I've made a tabbed application in Xcode 4.3 which works as deired. But I previously made a simple UIWebView application, that I would now like to implement into one of the tabs on the new application.
This is what I've done in the classes for FirstViewController:
// FirstViewController.h
// SafeLine
//
// Created by Camilla Fröberg on 2012-03-27.
// Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController {
IBOutlet UIWebView *webDisplay;
}
#property(nonatomic,retain) UIWebView *webDisplay;
#end
And the FirstViewController.m:
// FirstViewController.m
// SafeLine
//
// Created by Camilla Fröberg on 2012-03-27.
// Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webDisplay;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webDisplay loadRequest:requestObj];
[super viewDidLoad];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#end
When running the application I won't get any error message, and it will not show the website, instead it will only show an empty view...
Any help is appreciated!
// Best regards
Camilla from Sweden
I think, you should check if you connected the UIWebView in the Interface Builder with IBOutlet.