标签: xcode4

单击子项时如何一次获取父视图标签和子标签?

我已经动态创建了视图,并在其中动态创建了按钮。单击按钮时,我必须同时获取视图和按钮的标签。我已经将代码用作

-(void)addButton
{
    for (int j=0; j<[defaultNumberAry count]; j++) {

    numberButton=[[UIButton alloc]initWithFrame:CGRectMake(n, 0, 40, 40)];
    n=n+42;
    [numberButton setBackgroundImage:[defaultNumberAry objectAtIndex:j] forState:UIControlStateNormal];
    numberButton.tag=j;
    [numberTagAry addObject:[NSString stringWithFormat:@"%d",j]];
    numberButton.userInteractionEnabled = YES;
    [numberButton addTarget:self action:@selector(pressed:) forControlEvents:UIControlEventTouchUpInside];
    numberButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
    [numberView addSubview:numberButton];

}
}
-(void)addView:(int)yv
{
n=22;
numberView=[[UIView alloc]initWithFrame:CGRectMake(300, yv, 400, 44)];
numberView.backgroundColor=[UIColor yellowColor];
numberView.tag=b;
b++;
numberView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touched:)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[numberView addGestureRecognizer:tapGestureRecognizer];

}
-(void)pressed:(id)sender{
    UIButton *button …
Run Code Online (Sandbox Code Playgroud)

objective-c ios xcode4

0
推荐指数
1
解决办法
3797
查看次数

如何在xcode中访问其他viewcontrollers变量/属性

我知道之前已经问过类似的问题,但请跟我一起,因为我在Objective C上是全新的(对C有很好的了解).

我的情况是我有一个带有两个窗口的标签栏控制器.当我在"秒"按下按钮时,我改变了一个变量changeName.我想使用changeName我的"第一个"视图控制器中的值,但偶然发现了一些问题:

为了达到另一个viewcontroller,我发现这是从SO(不幸的是我忘了在哪里):

-(NSString *)newName{

// Create a UIStoryboard object of "MainStoryBoard_iPhone" named storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:(NSString *)@"MainStoryBoard_iPhone" bundle:(NSBundle *)nil];

// Create a UIViewController object of the wanted element from MainStoryBoard_iPhone
UIViewController *secondview = [storyboard instantiateViewControllerWithIdentifier:(NSString *)@"secondBoard"];

return secondview.changeName;
}
Run Code Online (Sandbox Code Playgroud)

我在我的第一个.MainStoryBoard_iPhone是.xib/storyboard文件的名称.

但不是.错误说

Property 'changeName' not found on object of type 'UIViewController *'
Run Code Online (Sandbox Code Playgroud)

在我的第二个.我有

 @property (readwrite, retain) NSString *changeName;
Run Code Online (Sandbox Code Playgroud)

在第二天

 @synthesize changeName;
Run Code Online (Sandbox Code Playgroud)

感谢所有帮助,但请记住,我只使用OOP两天.谢谢大家

编辑:我应该在这里输入什么?

 - (void)viewDidLoad
{
[super viewDidLoad];
mylabel.text = Name; …
Run Code Online (Sandbox Code Playgroud)

objective-c uiviewcontroller ios4 xcode4 xcode4.2

0
推荐指数
1
解决办法
4538
查看次数

在XCode 4.3中调用'sqrt'没有匹配函数

我正在尝试使用C++为Mac制作SDL游戏.我已经完成了与SDL相关的所有工作,但是当我尝试使用sqrt函数时,我得到了错误no matching function for call to 'sqrt'.这是我的包含列表和我的第一个函数(main()函数现在没有真正做任何事情):

#include <iostream>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <math.h>

#include "geometry.h"

using namespace std;

void drawLine(vector2 start, vector2 end)
{
    double x = end.x - start.x;
    double y = end.y - start.y;
    double length = sqrt(x*x, y*y); // I get the error here
}
Run Code Online (Sandbox Code Playgroud)

我也试过导入相同的结果.有什么特别的我必须在Mac(Lion,XCode 4.3)上做这个工作吗?

编辑:为了完整性,geometry.h包含vector2结构的定义

c++ macos standard-library xcode4

0
推荐指数
1
解决办法
3851
查看次数

使用开关时出现问题

我有两个视图控制器和笔尖.我用一个切换开关填充了一个视图控制器,并在其头文件中声明了这一点:

@public UISwitch *toggleSwitch;
Run Code Online (Sandbox Code Playgroud)

并将其暴露为这样的属性:

@property (nonatomic,retain) IBOutlet UISwitch *toggleSwitch;
Run Code Online (Sandbox Code Playgroud)

我还将开关与toggleSwitch插座连接起来.然后我在我的其他视图控制器中使用此开关,如下所示:

theViewControllerWhereIDeclaredTheSwitch.toggleSwitch.on = YES;
Run Code Online (Sandbox Code Playgroud)

虽然默认情况下开关处于开启状态时一切正常,但是当我关闭开关时,它会在main.m文件中引发异常:"线程1:信号SIGABRT".我在使用Xcode时经常遇到这个错误,这个错误真是我的屁股.请帮忙.

xcode cocoa-touch objective-c uiswitch xcode4

0
推荐指数
1
解决办法
79
查看次数

XCode 4.2:实现上下文中缺少语义问题'@end',程序中出现意外的'@'

我是XCODE的新手,但我正在努力学习.基本上我的项目是Nada Jaksic在iPhone上创建基于表格的表格的返工".我很高兴知道我的编码出错了,这样我就可以从错误中吸取教训.任何和所有帮助都绝对值得赞赏!

从SignupTableViewController.h文件:

#import <UIKit/UIKit.h>

@interface SignupTableViewController : UITableViewController<UITextFieldDelegate,   UIActionSheetDelegate>

{


    IBOutlet UITableViewCell *cellExaminername;
    IBOutlet UITableViewCell *cellExamineraddress;
    IBOutlet UITableViewCell *cellExaminercity;
    IBOutlet UITableViewCell *cellExaminerstate;
    IBOutlet UITableViewCell *cellExaminerzip;
    IBOutlet UITableViewCell *cellExamineremail;
    IBOutlet UITableViewCell *cellSearchthroughdate;
    IBOutlet UITableViewCell *cellTitleheldby;
    IBOutlet UITableViewCell *cellPropertyaddress1;
    IBOutlet UITableViewCell *cellPropertyaddress2;
    IBOutlet UITableViewCell *cellPropertycity;
    IBOutlet UITableViewCell *cellPropertystate;
    IBOutlet UITableViewCell *cellProperyzip;
    IBOutlet UITableViewCell *cellTitlesearchnotes;    



    IBOutlet UITextField* txtExaminername;
    IBOutlet UITextField* txtExamineraddress;
    IBOutlet UITextField* txtExaminercity;
    IBOutlet UITextField* txtExaminerstate;
    IBOutlet UITextField* txtExaminerzip;
    IBOutlet UITextField* txtExamineremail;
    IBOutlet UITextField* txtSearchthroughdate;
    IBOutlet UITextField* txtTitleheldby;
    IBOutlet UITextField* txtPropertyaddress1; …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c xcode4 xcode4.2

0
推荐指数
1
解决办法
935
查看次数

XCode - 如果我的程序在模拟器o设备中运行,请检查常量

可能重复:
如何以编程方式确定我的应用程序是否在iphone模拟器中运行?

如果我的程序在模拟器o设备上运行,我如何用常量检查XCode 4?像这样的东西:

#ifdef RUNING_ON_DEVICE
#else
#endif
Run Code Online (Sandbox Code Playgroud)

objective-c xcode4

0
推荐指数
1
解决办法
809
查看次数

如何在iOS 6中获取默认日历的名称/ ID

我的iPad上有两(2)个日历(iCal)(一个个人,一个用于应用程序).它们与我的iMac同步,仅用于测试.(节省我在特定应用程序日历中输入的时间).

我目前正在编写一个需要访问应用程序日历的应用程序.它是iPad上的主要日历.我试图让Apple的SimpleEKDemo(未经修改)与应用程序的日历一起工作,但到目前为止我甚至不能让它不崩溃,更不用说返回任何东西了.我几个小时以来一直在关注谷歌和SO问题,并决定是时候召唤大枪了.

这是它崩溃的代码:

- (void)viewDidLoad
{
    self.title = @"Events List";

    // Initialize an event store object with the init method. Initilize the array for events.
    self.eventStore = [[EKEventStore alloc] init];

    self.eventsList = [[NSMutableArray alloc] initWithArray:0];

    // Get the default calendar from store.
    self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];  //  <---- crashes here    --------

    //  Create an Add button
    UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
                                      UIBarButtonSystemItemAdd target:self action:@selector(addEvent:)];
    self.navigationItem.rightBarButtonItem = addButtonItem;
    [addButtonItem release];

    self.navigationController.delegate = self;

    // Fetch today's event on selected calendar …
Run Code Online (Sandbox Code Playgroud)

icalendar objective-c xcode4

0
推荐指数
1
解决办法
6218
查看次数

如何删除UITableView中的额外行?

我有一个UITableView我正在加载它NSMutableArray.我希望删除额外的行,即我只希望将对象的计数数量array显示为行.如果我有3个对象,array我想只显示3行UITableView.但我可以看到除了计数对象之外还添加了额外的空行.我可以array这样做吗?

iphone uitableview xcode4

0
推荐指数
1
解决办法
2051
查看次数

Interface Builder IBOutlet - 没有@synthesize

我正在使用XCode 4.4.1来学习iPhone开发.

我正在我的ABCViewController.h标题中创建出口属性,方法是从UIObject的弹出菜单中的"引用出口"部分拖动.这增加了如下行:

@property (strong, nonatomic) IBOutlet UITextField *nameField;
Run Code Online (Sandbox Code Playgroud)

到头文件.

现在,当我查看相应的ABCViewController.m文件时,我期待看到

@synthesize nameField; 
Run Code Online (Sandbox Code Playgroud)

在某处自动生成.但事实并非如此 - 我必须手动添加每个@synthesize语句.

这只是一个小小的问题,但我想知道出了什么问题.

有任何想法吗?

iboutlet ios xcode4

0
推荐指数
1
解决办法
537
查看次数

对于关键视图,此类不符合键值编码

我是XCode的新手,我正在尝试构建我的第一个(严重的非示例应用程序).最后几天,我参加了一个关于XCode的研讨会,我正在尝试按照我们在示例中所做的确切步骤来构建我自己的应用程序.

我遇到以下问题:当我尝试运行应用程序时,我收到以下错误:

由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:此类不是键视图的键值编码兼容.

我正在创建一个新项目,我插入一个新的.h,.m和xib文件(新文件 - > Obkective-C类,类:ASViewController,子类UIViewController,我还检查With XIB用户界面)

我把我的xib文件留空了!里面没有控件.

我转到ASAppDelegate.m,我正在与我的xib文件建立连接,以便使用此xib文件运行应用程序.

#import "AS_MainViewController.h" 
#import "ASAppDelegate.h"

@implementation INGAppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

AS_MainViewController *MyrootViewController = [[AS_MainViewController alloc]
                        initWithNibName:@"AS_MainViewController" bundle: [NSBundle mainBundle]];

self.window.rootViewController = MyrootViewController;

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Run Code Online (Sandbox Code Playgroud)

我的ASAppDelegate.h是这样的:

#import <UIKit/UIKit.h>

@interface ASAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode4

0
推荐指数
1
解决办法
4478
查看次数