我试图在Objective-C中乘以两个矩阵.我已经将加速框架导入了我在Xcode中的项目,一切都编译得很好.我在我的计算器上进行了矩阵乘法并得到了正确的值,但是,在运行代码时,我没有.这就是我定义矩阵的方式..
float matrixA [3][3] = {{-.045, -.141, -.079}, {-.012, -.079, .0578}, {.112, -.011, -.0830}};
float matrixB [3][1] = {{40}, {-61}, {98}};
Run Code Online (Sandbox Code Playgroud)
然后我在加速框架中使用了mmul函数.
vDSP_mmul(&matrixA[3][3], 1, &matrixB[3][1], 1, &results[3][1], 1, 3, 1, 3);
Run Code Online (Sandbox Code Playgroud)
通过执行以下操作创建了数组结果.
float results[3][1];
Run Code Online (Sandbox Code Playgroud)
我只是把它放在一个空项目的viewDidLoad方法中,所以我可以NSLog结果.所以当我将matrixA乘以matrixB时,我得到以下结果..(-1,10,-3).但是,NSLog中的结果显示(-0.045,0.000,0.000).这是不正确的,我不明白为什么.我的理解是这个函数会将两个矩阵相乘.但我不确定它在做什么.我可能输错了东西,并希望有人可以帮助我.
侧注:matrixA实际上是另一个矩阵的逆.但是,我在加速框架中找不到任何反向的东西.我找到了一个叫做的函数
sgetrf_
Run Code Online (Sandbox Code Playgroud)
与LAPACK,但不是真的得到它.如果有人有任何帮助,建议或一些教程可以遵循我会很感激,已经在这三天了,现在在互联网上寻找东西!
我昨天问了这个问题,得到了Eric Skroch的一些帮助.但是,在查看Core Plot网站上的所有文档以及一些示例后,我仍然有点困惑.所以我将发布到目前为止的代码,看看是否有人可以帮我一些.也许Eric也会更容易帮助.我的问题是我需要删除一个情节,然后在选项卡式应用程序中将其替换为另一个情节.Eric和其他人说过要使用reloadData方法.但我不知道我的代码可以在哪里使用它?这是我的标题和实现文件.
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface GraphViewController : UIViewController <CPTPlotDataSource>
@property (nonatomic, strong) CPTGraphHostingView *hostView;
@property (nonatomic, strong) NSMutableArray *myData;
@property (nonatomic) float XAXISMIN;
@property (nonatomic) float XAXISMAX;
@property (nonatomic) float YAXISMIN;
@property (nonatomic) float YAXISMAX;
@property (strong, nonatomic) IBOutlet UILabel *noGraph;
@end
Run Code Online (Sandbox Code Playgroud)
和
#import "GraphViewController.h"
#import "MyVariables.h" // a singleton class for my variables
@interface GraphViewController ()
@end
@implementation GraphViewController
@synthesize hostView = _hostView;
@synthesize myData = _myData;
@synthesize XAXISMIN;
@synthesize XAXISMAX;
@synthesize YAXISMAX;
@synthesize noGraph;
@synthesize …Run Code Online (Sandbox Code Playgroud) 我只是在制作转换应用程序时啧啧称道.这很好,但我想扩展它.你输入一个华氏值,然后转换为摄氏度.很基本的.所以我也希望添加开尔文转换.但是代码只允许你插入一个华氏数字.因此,在添加开尔文文本字段后,我想检查哪个文本框中包含文本.所以我使用了以下代码:
- (IBAction)convert:(id)sender
{
if ([fahrenheit isFirstResponder])
{
float x = [[fahrenheit text] floatValue];
float y = (x - 32.0f) * (5.0f/9.0f); //celcius
float z = y + 273.15f; //kelvin
[celcius setText:[NSString stringWithFormat:@"%3.2f" , y]];
[kelvin setText:[NSString stringWithFormat:@"%3.2f" , z]];
[fahrenheit resignFirstResponder];
} else if ([celcius isFirstResponder])
{
float x = [[celcius text] floatValue];
float y = 32.0f + ((9.0f/5.0f) * x); //farenheit
float z = x + 273.12f; //kelvin
[fahrenheit setText:[NSString stringWithFormat:@"%3.2f" , y]];
[kelvin setText:[NSString stringWithFormat:@"%3.2f" , z]]; …Run Code Online (Sandbox Code Playgroud) 我刚刚完成了我的应用程序,并添加了一些伟大的东西与核心情节和他们的专职人员的帮助.我的问题涉及使用视网膜显示器的图像.我有一个注释,是一个讲话泡泡的图片.当我在模拟器中运行应用程序时,它显示正常分辨率,但当我切换到视网膜时,图像被裁剪.见下图.我有一个.png,我称之为Bubble,我又添加了另一个名为Bubble @ 2x的大小两倍,我认为这是我需要做的.那没用.所以我试着设置view.contentScale,见下面的代码.但似乎没有任何效果.任何人都有任何想法,我忘了做什么?再次感谢.
{
//first annotation
NSValue *value = [self.myData objectAtIndex:index];
CGPoint point = [value CGPointValue];
NSString *number1 = [NSString stringWithFormat:@"(%.2f, ", point.x];
NSString *number2 = [NSString stringWithFormat:@"%.2f)", point.y];
NSNumber *x = [NSNumber numberWithFloat:point.x];
NSNumber *y = [NSNumber numberWithFloat:point.y];
NSArray *anchorPoint = [NSArray arrayWithObjects: x, y, nil];
NSString *final = [number1 stringByAppendingString:number2];
//second annotation
UIImage *bubble = [UIImage imageNamed:@"Bubble.png"];
CPTImage *fillimage = [CPTImage imageWithCGImage:bubble.CGImage];
CPTBorderedLayer *imageLayer = [[CPTBorderedLayer alloc] init];
//imageLayer.contentsScale = [[UIScreen mainScreen] scale]; //tried this
imageLayer.frame = CGRectMake(0, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个应用程序,用户可以从其图像库中选择一个用作背景的图像,然后是他们的徽标,他们也可以从他们的(照片)库中选择...
目前我还没有找到可以帮助我的教程,主要是因为用户必须能够设置自己的图像而不是默认图像.另外,你们中的任何人也知道如何拥有多个UIImagePickerControllers,因为这个代码同时影响两个图像而不是每个选择器一个?
我使用/拥有的东西:
我使用swift
我使用xcode 7.0.1
这是
我目前使用的故事板.
我的swift文件:
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var logo: UIImageView!
@IBOutlet weak var bgimg: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func selectbg(sender: AnyObject) {
let bgPicker = UIImagePickerController()
bgPicker.delegate = self
bgPicker.sourceType = .PhotoLibrary
self.presentViewController(bgPicker, animated: true, completion: nil)
}
@IBAction func selectlogo(sender: AnyObject) {
let logoPicker = UIImagePickerController()
logoPicker.delegate = self
logoPicker.sourceType = .PhotoLibrary
self.presentViewController(logoPicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, …Run Code Online (Sandbox Code Playgroud) 我有一个 NSDictionary,我想从中取出一些字符串。字典的名字叫做推文。我可以通过执行以下操作来获取用户名和推文。
NSDictionary *tweet = self.detailItem;
NSString *username = [[tweet objectForKey:@"user"] objectForKey:@"name"];
NSString *tweetText = [tweet objectForKey:@"text"];
Run Code Online (Sandbox Code Playgroud)
如果我 NSLog 我得到的结果;用户名是“人的用户名”,tweetText 是“人的推文”。这些都是我可以操作的 NSString。
但是,我还需要从推文中获取实际 URL,而不是缩短的 URL。所以我在字典中找到了 valueForKeyPath。我需要它作为一个字符串并尝试了以下操作。
NSString *url = [tweet valueForKeyPath:@"entities.urls.display_url"];
Run Code Online (Sandbox Code Playgroud)
我也可以 NSLog 并获得正确的信息。但我认为它是一个数组?NSLog 看起来像这样.. url 是(“url 到这里”)。用括号和引号。这与其他字符串不同。我假设这是因为 valueForKeyPath。当我尝试使用 url hasPrefix 时,它不喜欢那样,并提到您不能将 hasPrefix 与数组一起使用。但我也尝试将多个 objectForKey 与实体、url 和 display_url 一起使用。但这不起作用。有什么方法可以让我输入字符串格式。我查看了一些 SO 问题和网络,但找不到任何对我有用的东西。任何帮助将不胜感激。谢谢你的时间
我目前正在更新我的一个应用程序.它从Internet获取信息,并使用networkActivityIndicatorVisible显示和隐藏状态栏中的活动指示器.我们收到的一个抱怨是,它太小了,用户不知道他们的设备正在获取信息.所以我的想法是在我的视野中使用旋转活动轮.如果你试图从项目中拖出一个,它会将它放在一个单元格中,或者放在我制作的标题UIView中.这不是我想要的,所以我以编程方式制作它.
在头文件中.
@property (strong, nonatomic) UIActivityIndicatorView *mySpinner;
Run Code Online (Sandbox Code Playgroud)
在实现文件中.
_mySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_mySpinner.color = [UIColor blackColor];
_mySpinner.translatesAutoresizingMaskIntoConstraints = NO;
_mySpinner.hidesWhenStopped = YES;
Run Code Online (Sandbox Code Playgroud)
然后我通过执行以下操作将旋转轮添加到我的视图中.随着我的约束.
[self.view addSubview:_mySpinner];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_mySpinner
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_mySpinner
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:0.75
constant:0]];
[_mySpinner startAnimating];
Run Code Online (Sandbox Code Playgroud)
我运行代码,它工作正常.即使我旋转旋转器也是我想要的地方.然而,这就是问题所在,当我滚动表格视图时,微调器随之而来!
我知道这是因为我将微调器添加到self.view并使用self.view进行了所有约束.在UITableViewController的情况下,表视图是self.view.
该应用程序有几个表格视图,它们都很长,很多都有自定义单元格.我真的不想重新设计所有内容,但是有没有人知道UITableViewController是否有超级视图我可以将我的约束放到?我尝试了几件事,但没有任何工作.抱歉这么长的问题,但我希望有人可以提供帮助.谢谢阅读!
ios ×6
core-plot ×2
objective-c ×2
image ×1
ios5 ×1
iphone ×1
matrix ×1
nsdictionary ×1
nsstring ×1
overlay ×1
photolibrary ×1
swift ×1
uitableview ×1
uitextfield ×1
xcode ×1