我在NSTableView中使用了几个NSButtonCell对象.它们是简单的方形按钮,上面有自定义图像.
这些按钮在未突出显示时正确绘制:所有可见的是图像,按钮矩形的其余部分是透明的.但是,当我单击它们时,整个按钮矩形会突出显示,反转透明部分的背景.
我希望看到倒置的图像,透明部分保持透明.如何才能做到这一点?
我有一些看起来像这样的代码:
actualColor = 0;
targetColors = [NSArray arrayWithObjects:[UIColor blueColor],
[UIColor purpleColor],
[UIColor greenColor],
[UIColor brownColor],
[UIColor cyanColor], nil];
timer = [NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:@selector(switchScreen)
userInfo:nil
repeats:YES];
Run Code Online (Sandbox Code Playgroud)
在选择器中我有这个:
- (void) switchScreen
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
int totalItens = [targetColors count];
NSLog(@"Total Colors: %i",totalItens);
if(actualColor >= [targetColors count])
{
actualColor = 0;
}
UIColor *targetColor = [targetColors objectAtIndex:actualColor];
if(!firstUsed)
{
[firstView setBackgroundColor:targetColor];
[secondView setAlpha:0.0];
[firstView setAlpha:1.0];
firstUsed = YES;
}
else
{
[firstView setBackgroundColor:targetColor];
[secondView setAlpha:1.0];
[firstView setAlpha:0.0]; …Run Code Online (Sandbox Code Playgroud) 我想要一个实例变量对象来采用协议.
@interface GameScene : Scene <AVAudioPlayerDelegate> {
@private
Layer *content <CocosNodeOpacity>;
}
Run Code Online (Sandbox Code Playgroud)
例如,我希望我的Layer对象采用,<CocosNodeOpacity>以便我可以获取方法
-(GLubyte) opacity; //and
-(void) setOpacity: (GLubyte) opacity;
Run Code Online (Sandbox Code Playgroud)
免费.上面显示的语法无效.是否可以在不创建新实现文件和创建自定义对象的情况下实现此目的?谢谢.
我有以下目标C类.这是为了在电影风格设置,标题场地ID等电影上存储信息.每当我尝试创建这个类的对象时:
Film film = [[Film alloc] init];
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:variable-sizedobject可能无法初始化,静态分配Objective-C类"Film"的实例,静态分配Objective-C类"Film"的实例.
我对Objective C很新,可能仍然处于C#思维模式中,有谁能告诉我我做错了什么?
谢谢迈克尔
码:
// Film.m
#import "Film.h"
static NSUInteger currentID = -1;
@implementation Film
@synthesize filmID, title, venueID;
-(id)init {
self = [super init];
if(self != nil) {
if (currentID == -1)
{
currentID = 1;
}
filmID = currentID;
currentID++;
title = [[NSString alloc] init];
venueID = 0;
}
return self;
}
-(void)dealloc {
[title release];
[super dealloc];
}
+(NSUInteger)getCurrentID {
return currentID;
}
+(void)setCurrentID:(NSUInteger)value {
if (currentID != value) …Run Code Online (Sandbox Code Playgroud) 我有一个情况,我必须处理touchesBegan文本字段.此文本字段位于scrollview中.
到目前为止我试过这个:
我创建了UIScrollView的子类
@interface CustomScrollView : UIScrollView
{
}
@end
@implementation CustomScrollView
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"good");
}
@end
Run Code Online (Sandbox Code Playgroud)
在这里,我可以得到理想的结果.
我用textfields实现了同样的东西.我做了一个子类UITextField:
@interface CustomTextField : UITextField
{
}
@end
@implementation CustomTextField
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"good");
}
@end
Run Code Online (Sandbox Code Playgroud)
如果文本字段在普通视图中,这可以正常工作,但是当文本字段位于常规scrollView或我的自定义scrollview中时,它会失败.
请赐教我这个
(我这样做是为了在用户长按文本字段时获得类似的内容,文本字段中的文本从Textfield分配到标签,用户可以将此标签拖到视图中的其他位置)
我有一组结构,定义如下:
typedef struct
{
int index;
int array[10];
}
Item;
typedef struct
{
Item A;
Item B;
Item C;
}
Collection;
Run Code Online (Sandbox Code Playgroud)
我想声明一个类型的变量,Collection如下所示:
Collection collection =
{
{ 1, 0 }, /* item A */
{ 2, 0 }, /* item B */
{ 3, 0 } /* item C */
};
Run Code Online (Sandbox Code Playgroud)
这会将三个index变量设置为1,2和3,同时将所有三个array[]变量初始化为零吗?
它似乎正在我的编译器上工作,但我想知道这是否是标准行为.
我需要检查一下特定的位置,NSArray看看它们是否已经初始化,但我遇到了麻烦.我尝试执行以下操作,但它会导致我的应用程序崩溃!
if ((NSMutableArray *)[arrAllBlocks objectAtIndex:iLine] == nil)
{
[arrAllBlocks insertObject:[[NSMutableArray alloc] init] atIndex:iLine];
}
NSMutableArray *columArray = (NSMutableArray *)[arrAllBlocks
objectAtIndex:iLine];
[columArray insertObject:newBlock atIndex:iColumn];
Run Code Online (Sandbox Code Playgroud)
这样做最好的是什么?我已经尝试了一些像这样的方法isValid!
在Cocoa中,当计算机有多个屏幕时,如何确定哪个屏幕保持菜单栏?
这是我到目前为止所拥有的:
NSArray * screens = [NSScreen screens];
NSScreen * mainScreen = [screens objectAtIndex:0];
if ([screens count] > 1)
{
for (NSScreen * screen in screens)
{
if (/* screen == the screen that holds the menubar */)
{ mainScreen = screen; break; }
}
}
NSLog(@"the main screen is: %@", mainScreen);
Run Code Online (Sandbox Code Playgroud)
注意:我尝试使用[NSScreen mainScreen],但它只返回当前活动窗口所在的屏幕.如果我的应用程序中没有打开其他窗口,它只返回具有菜单栏的屏幕.
对不起,这真让我感到困惑,我知道答案是盯着我看,我无法弄清楚.有人可以看看吗?它用于航空公司预订系统学校项目.
此功能接收航班号,容量,航班数量以及包含所有航班作为参数的向量.它将检查以确保航班不存在,如果存在则将显示错误消息,否则将创建航班.航班数量也将增加.
void newFlight( string f, string s, int* n, vector<Flight> *v)
{
Flight temp;
//Check to see if flight number exists
bool alreadyExist = false;
for (int i=0; i < v->size(); i++)
{
if (f.compare((v[i].getNumber()) == 0))
alreadyExist = true;
}
//If it doesn't exist, create it
if (!alreadyExist)
{
v->push_back (temp); //Add the new Flight object to the
//vector of flights
*n++; //Increase count
}
else
{
cout << "A flight numbered " << f << " already …Run Code Online (Sandbox Code Playgroud) 我创建了一个链表,当我尝试打印节点的值并使用NULL作为绑定时,它不起作用.例如:
#include <iostream>
typedef struct Node;
typedef Node* Node_ptr;
struct Node
{
int i;
Node_ptr next;
};
int main()
{
Node_ptr ptr, head;
ptr = new Node;
head = ptr;
// load
for(int j = 0; j < 4; j++)
{
ptr->next = new Node;
ptr->i = j;
ptr = ptr->next;
}
// print
ptr = head;
while(ptr->next != NULL)
{
std::cout << "print: " << ptr->i << std::endl;
ptr = ptr->next;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,代码会陷入while循环中的无限循环中.它永远不会理解链表只有5个节点长,它只是继续前进.我不明白为什么会这样.
我正在Objective-C中创建一个双向链表.我希望我的节点类包含一个实例方法,允许我在目标节点之后添加另一个节点,如下所示:
// start <-> nodeA <-> nodeB <-> nodeC <-> end
Node * newNode = [Node node];
[NodeB thisMethodNeedsAGoodName:newNode];
// start <-> nodeA <-> nodeB <-> newNode <-> nodeC <-> end
Run Code Online (Sandbox Code Playgroud)
这个方法有什么好名字?insertAfter:听起来不对,因为这意味着正在插入目标,而不是新节点.insertNode:没关系,除了我想写另一个方法在目标节点之前插入一个节点,然后我必须为该方法提出一个不同的名称.
有任何想法吗?