我正在通过2011年斯坦福秋季iOS课程:http: //www.stanford.edu/class/cs193p/cgi-bin/drupal/
我到作业#3: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/assignments/Assignment%203_2.pdf
作为总结,先前的任务已经要求建立一个常规计算器,现在这个任务要求我们将这个计算器推送到一个Nav控制器并从该CalculatorViewController创建一个segue到GraphViewController,它将绘制存储在"CalculatorBrain"中的函数.这个CalculatorBrain是原始CalculatorViewController的模型.
提示#5继续谈论的事实是,现在GraphViewController的模型与CalculatorViewController的模型不同,我无法弄清楚他的意思.
我能够构建新MVC的唯一方法是在GraphViewController的GraphView(视图)中创建一个带有ID类型为"dataSource"的对象的协议.然后在GraphViewController中:采用该协议,实例化GraphView并将自身设置为数据源:
-(void) setGraphView:(GraphView *)graphView
{
_graphView=graphView;
self.graphView.dataSource=self;
}
Run Code Online (Sandbox Code Playgroud)
然后在原始的CalculatoViewController中,使用prepareForSegue将程序传递给GraphViewController:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"Graph"])
{
GraphViewController *myGraphViewController = segue.destinationViewController;
myGraphViewController.myCalculator=self.myCalcBrain;
}
}
Run Code Online (Sandbox Code Playgroud)
所以这似乎工作正常.所以,如果这样做,那意味着GraphViewController的模型真的是原来的计算器大脑,他特别说它不是!
我的意思是,在segue期间,我将从原始的CalculatorViewController分配给Graphviewcontroller计算器属性计算器模型实例,然后使用协议将GraphViewController中的Y值返回到GraphView意味着该模型GraphViewController实际上只是原始的CalculatorBrain模型.
有没有像NSHomeDirectory()和NSTemporaryDirectory一样的快捷方法来到项目中的resources文件夹?
/ resources /文件夹是存储文件的最佳位置吗?
尝试在观看讲座10 iTunes视频的同时跟进并编写Smashtag项目代码.
当我将已下载的Twitter包添加到我的Smashtag项目时,当我在TweetTableViewController中引用它时,XCode找不到Tweet类.
由于上述问题,我将属于Twitter包的四个类分别添加到项目中.XCode找到了这四个类,但以这种方式添加它们会产生11个编译错误.
我正在使用iOS 8.3版本之后的XCode版本6.3(6D570).
还有其他人遇到过这个问题吗?
感谢您阅读我的问题.〜李
其中一项工作是在计算器上实现"sin"按钮添加以下4个操作按钮:•sin:计算堆栈顶部操作数的正弦值.
这是我的代码
- (double)performOperation:(NSString *)operation
{
double result = 0;
if ([operation isEqualToString:@"+"]) {
result = [self popOperand] + [self popOperand];
}else if ([@"*" isEqualToString:operation]) {
result = [self popOperand] * [self popOperand];
}else if ([operation isEqualToString:@"-"]) {
double subtrahend = [self popOperand];
result = [self popOperand] - subtrahend;
}else if ([operation isEqualToString:@"/"]) {
double divisor = [self popOperand];
if(divisor) result = [self popOperand] / divisor;
}else if([operation isEqualToString:@"sin"]){
double operd = [self popOperand];
NSLog(@"operd=%g",operd);
if(operd) result = sin(operd);
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Set Card Game 中绘制曲线。输出甚至不接近我想要的。我应该如何改进绘图?
..
#define SQUIGGLE_CURVE_FACTOR 0.5
- (UIBezierPath *)drawSquiggleAtPoint:(CGPoint)point
{
CGFloat dx = self.bounds.size.width * SYMBOL_WIDTH_RATIO / 2;
CGFloat dy = self.bounds.size.height * SYMBOL_HEIGHT_RATIO / 2;
UIBezierPath *path = [[UIBezierPath alloc] init];
CGFloat dsqx = dx * SQUIGGLE_CURVE_FACTOR;
CGFloat dsqy = dy * SQUIGGLE_CURVE_FACTOR;
[path moveToPoint:CGPointMake(point.x - dx, point.y)];
[path addQuadCurveToPoint:CGPointMake(point.x - dsqx, point.y + dsqy) controlPoint:CGPointMake(point.x - dx, point.y + dy + dsqy)];
[path addCurveToPoint:CGPointMake(point.x + dx, point.y) controlPoint1:point controlPoint2:CGPointMake(point.x + dx, …
Run Code Online (Sandbox Code Playgroud) 我有一个表视图,加载时创建一个人对象
Person.h
#import <UIKit/UIKit.h>
#import "TwitterHelper.h"
@interface Person : NSObject {
NSDictionary *userInfo;
NSURL *image;
NSString *userName;
NSString *displayName;
NSArray *updates;
}
/*
@property (retain) NSString *userName;
@property (retain) NSString *displayName;
@property (retain) NSDictionary *userInfo;
*/
@property (nonatomic, copy) NSURL *image;
@property (retain) NSArray *updates;
- (id)initWithUserName:userName;
@end
Run Code Online (Sandbox Code Playgroud)
Person.m
#import "Person.h"
@implementation Person
/*
@synthesize userName;
@synthesize displayName;
@synthesize userInfo;
*/
@synthesize image;
@synthesize updates;
- (id)initWithUserName:(NSString *)user{
userName = user;
userInfo = [TwitterHelper fetchInfoForUsername:user];
displayName = [userInfo valueForKey:@"name"];
image …
Run Code Online (Sandbox Code Playgroud) 这是我的头文件
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <PolygonShape.h>
@interface Controller : NSObject {
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
//IBOutlet PolygonShape *shape;
}
- (IBAction)decrease;
- (IBAction)increase;
@end
Run Code Online (Sandbox Code Playgroud)
这是我的实现文件
#import "Controller.h"
@implementation Controller
- (IBAction)decrease {
//shape.numberOfSides -= 1;
}
- (IBAction)increase {
//shape.numberOfSides += 1;
}
@end
Run Code Online (Sandbox Code Playgroud)
为什么我的#import "Controller.h"
线路上出现以下错误?
error: PolygonShape.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)
PolygonShape.h和.m文件与Controller类位于同一项目中,并位于同一目录中.
代码来自Stanford CS193p.我添加了一个NSLog来检查它.标签似乎没有初始化.任何的想法?
@interface AskerViewController() <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *questionLabel;
@property (weak, nonatomic) NSString *question;
@end
@implementation AskerViewController
@synthesize questionLabel = _questionLabel;
@synthesize question = _question;
- (void)setQuestion:(NSString *)question
{
_question = question;
self.questionLabel.text = question;
NSLog(@"label is %@", self.questionLabel);
}
@end
Run Code Online (Sandbox Code Playgroud)
NSLog结果是:
2012-07-31 01:56:45.177 Kitchen Sink[23931:f803] label is (null)
Run Code Online (Sandbox Code Playgroud) 我正在寻找在演讲10"性能和线程"中使用的Flickr多线程示例应用程序.他做了一些我想看的事情.我正在寻找的特定文件是ImageLoadingOperation.h和MyTableViewController.m?
有人知道他们是否存在于某处,我只是错过了吗?如果它们不存在,是否有人知道使用NSInvocationOperation并创建类以线程方式加载图像的一些好例子?
我正在研究斯坦福CS193p课程,我正在尝试绘制图表.绘制轴有效,但我无法绘制图形本身.我收到了消息
CGContextAddLineToPoint: no current point.
Run Code Online (Sandbox Code Playgroud)
当我试图画画.这是代码.
- (void)drawRect:(CGRect)rect
{
NSLog(@"Drawing Graph View");
CGPoint origin = CGPointMake(20, 350);
CGRect rect2 = CGRectMake(origin.x, origin.y, 250, -250);
[AxesDrawer drawAxesInRect:rect2 originAtPoint:origin scale:[self scale]];
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
CGContextSetLineWidth(context, 2);
[[UIColor redColor] setStroke];
CGContextMoveToPoint(context, origin.x, origin.y);
for (CGFloat i=0; i<250; i++) {
CGFloat yChange = [self.dataSource deltaY:self];
CGContextAddLineToPoint(context, origin.x+i, origin.y-yChange);
CGContextStrokePath(context);
}
UIGraphicsPopContext();
}
Run Code Online (Sandbox Code Playgroud) cs193p ×10
objective-c ×8
iphone ×5
ios ×4
cocoa ×2
drawing ×1
drawrect ×1
filesystems ×1
import ×1
init ×1
memory-leaks ×1
setter ×1